Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
A clipboard management CLI tool built with Polysemy, Servant and GI.Gtk.
Synopsis
- data Agent :: Effect
- data AgentTag
- type Agents = [Agent @@ AgentTmux, Agent @@ AgentX, Agent @@ AgentNet]
- data XClipboard :: Effect
- data Gtk s :: Effect
- data GtkMain (s :: Type) :: Effect
- data GtkClipboard :: Effect
- interpretAgentNet :: Members [Manager, Reader NetConfig] r => Members [Log, Interrupt, Race, Resource, Async, Embed IO, Final IO] r => InterpreterFor Agent r
- interpretAgentX :: Members [EventConsumer XClipboardEvent, Events Event, Reader InstanceName, XClipboard !! Text] r => Members [ChronosTime, Log, Race, Resource, Async] r => InterpreterFor Agent r
- interpretAgentTmux :: Members [Reader TmuxConfig, Log, Resource, Race, Async, Embed IO] r => InterpreterFor Agent r
- interpretXClipboardGtk :: Members [Scoped_ GtkClipboard !! Text, Log, Embed IO, Final IO] r => InterpreterFor (XClipboard !! Text) r
- interpretGtk :: Members [Reader X11Config, Resource, Log, Embed IO] r => InterpreterFor (Scoped_ (Gtk Display) !! Text) r
- interpretGtkMain :: forall s wait restart r. TimeUnit wait => TimeUnit restart => Members [Mask, Resource, Race, Embed IO] r => wait -> restart -> InterpreterFor (GtkMain s) r
- handleGtkMain :: forall s wait restart e m r a. TimeUnit wait => TimeUnit restart => Members [Resource, Lock, Sync StartGtkMain, Sync (GtkResource s)] r => wait -> restart -> GtkMain s m a -> Tactical e m r a
- interpretGtkClipboard :: Members [GtkMain Display, Log, Embed IO, Final IO] r => InterpreterFor (Scoped_ GtkClipboard !! Text) r
- handleGtkClipboard :: Members [Log, Embed IO, Final IO] r => Display -> GtkClipboard (Sem r0) a -> Tactical effect (Sem r0) (Stop Text ': r) a
- data Event
- data Selection
- transformXEvents :: Members [EventConsumer XClipboardEvent, Reader InstanceName] r => Members [Events Event, XClipboard !! Text, Log, ChronosTime, Resource, Race, Async] r => Sem r a -> Sem r a
- subscribeToClipboard :: Members [Reader Display, Log, Stop Text, Embed IO, Final IO] r => (Selection -> Text -> Sem r ()) -> Selection -> Sem r ()
- gtkMainLoop :: Members [Scoped_ (Gtk s) !! Text, GtkMain s, Log, Race, Resource, Async] r => Sem r () -> Sem r a -> Sem r a
- type Api = "event" :> (Get '[JSON] [Event] :<|> ((ReqBody '[JSON] Event :> PostCreated '[JSON] NoContent) :<|> (ReqBody '[JSON] Int :> PutAccepted '[JSON] (Maybe Event))))
- serve :: Members [History, Reader NetConfig, Sync ServerReady, Log, Interrupt, Final IO] r => Sem r ()
- listen :: Members [EventConsumer Event, History, Sync Listening] r => Sem r ()
- yank :: Members [Reader InstanceName, Client, ChronosTime, Log, Error Text, Embed IO] r => YankConfig -> Sem r ()
Documentation
Helic is primarily a CLI tool that listens for clipboard events and broadcasts them to other hosts and tmux.
The program is built with Polysemy, so its effects and interpreters may be useful for other developers. Some utilities for interfacing with GTK are exposed as well.
An agent is an interface to an external entity that can receive clipboard events. The Helic CLI uses agents for remote hosts over network, tmux, and X11.
type Agents = [Agent @@ AgentTmux, Agent @@ AgentX, Agent @@ AgentNet] Source #
The default agents for the Helic CLI.
XClipboard
data XClipboard :: Effect Source #
Communicate with the X11 clipboard.
Gtk
This effect is a utility for running the GTK main loop in a resource-safe manner.
GtkMain
data GtkMain (s :: Type) :: Effect Source #
This effect is a communication bridge between Gtk
and GTK functionality effects like GtkClipboard
.
It does not directly interact with the GTK API, but allows a scope to ensure that the GTK main loop is running and to
access its resource (usually a display handle).
GtkClipboard
data GtkClipboard :: Effect Source #
This effect GtkClipboard
allows an app to read from, write to, and subscribe to events from a clipboard.
It is intended to be scoped with a GTK display by interpretWithGtk
.
Interpreters
interpretAgentNet :: Members [Manager, Reader NetConfig] r => Members [Log, Interrupt, Race, Resource, Async, Embed IO, Final IO] r => InterpreterFor Agent r Source #
Interpret Agent
using remote hosts as targets.
This also starts the HTTP server that listens to network events, which are used both for remote hosts and CLI
events.
interpretAgentX :: Members [EventConsumer XClipboardEvent, Events Event, Reader InstanceName, XClipboard !! Text] r => Members [ChronosTime, Log, Race, Resource, Async] r => InterpreterFor Agent r Source #
Interpret Agent
using the X11 clipboard as target.
This interpreter also runs a thread that converts events generated by the XClipboard
interpreter
(XClipboardEvent
) to the main Event
type.
interpretAgentTmux :: Members [Reader TmuxConfig, Log, Resource, Race, Async, Embed IO] r => InterpreterFor Agent r Source #
Interpret Agent
using a tmux server as the target.
interpretXClipboardGtk :: Members [Scoped_ GtkClipboard !! Text, Log, Embed IO, Final IO] r => InterpreterFor (XClipboard !! Text) r Source #
Interpret XClipboard
using a GTK backend.
This uses the library gi-gtk
to access the X11 clipboard.
interpretGtk :: Members [Reader X11Config, Resource, Log, Embed IO] r => InterpreterFor (Scoped_ (Gtk Display) !! Text) r Source #
interpretGtkMain :: forall s wait restart r. TimeUnit wait => TimeUnit restart => Members [Mask, Resource, Race, Embed IO] r => wait -> restart -> InterpreterFor (GtkMain s) r Source #
Interpret the GTK main loop communication bridge with MVar
s.
handleGtkMain :: forall s wait restart e m r a. TimeUnit wait => TimeUnit restart => Members [Resource, Lock, Sync StartGtkMain, Sync (GtkResource s)] r => wait -> restart -> GtkMain s m a -> Tactical e m r a Source #
Interpret the GTK main loop communication bridge with MVar
s.
interpretGtkClipboard :: Members [GtkMain Display, Log, Embed IO, Final IO] r => InterpreterFor (Scoped_ GtkClipboard !! Text) r Source #
Native interpreter for GtkClipboard
that requires the effect to be used within a withGtkClipboard
region.
handleGtkClipboard :: Members [Log, Embed IO, Final IO] r => Display -> GtkClipboard (Sem r0) a -> Tactical effect (Sem r0) (Stop Text ': r) a Source #
This handler for GtkClipboard
depends on a Display
, which should optimally be provided by a Scoped
interpreter to ensure safe acquisition of the resource.
The effect then needs to be scoped using withGtkClipboard
.
The default implementation for this purpose is interpretWithGtk
.
Data
The central data type representing a clipboard event.
This type enumerates the different types of basic clipboards that X11 operates on.
Clipboard | Usually the target of explicit copy commands (ctrl-c). |
Primary | Stores the cursor selection. |
Secondary | Only used in exotic situations. |
Instances
Bounded Selection Source # | |
Enum Selection Source # | |
Defined in Helic.Data.Selection succ :: Selection -> Selection # pred :: Selection -> Selection # fromEnum :: Selection -> Int # enumFrom :: Selection -> [Selection] # enumFromThen :: Selection -> Selection -> [Selection] # enumFromTo :: Selection -> Selection -> [Selection] # enumFromThenTo :: Selection -> Selection -> Selection -> [Selection] # | |
Show Selection Source # | |
Eq Selection Source # | |
Ord Selection Source # | |
Defined in Helic.Data.Selection |
Utilities
transformXEvents :: Members [EventConsumer XClipboardEvent, Reader InstanceName] r => Members [Events Event, XClipboard !! Text, Log, ChronosTime, Resource, Race, Async] r => Sem r a -> Sem r a Source #
Listen for XClipboardEvent
s and publish them as Event
s.
subscribeToClipboard :: Members [Reader Display, Log, Stop Text, Embed IO, Final IO] r => (Selection -> Text -> Sem r ()) -> Selection -> Sem r () Source #
Listen to clipboard events for a specific source, like "primary selection", and pass them to the callback.
gtkMainLoop :: Members [Scoped_ (Gtk s) !! Text, GtkMain s, Log, Race, Resource, Async] r => Sem r () -> Sem r a -> Sem r a Source #
Run loopGtkMain
in a thread.
type Api = "event" :> (Get '[JSON] [Event] :<|> ((ReqBody '[JSON] Event :> PostCreated '[JSON] NoContent) :<|> (ReqBody '[JSON] Int :> PutAccepted '[JSON] (Maybe Event)))) Source #
The Servant API of the daemon, providing endpoints for getting all events and creating one.
serve :: Members [History, Reader NetConfig, Sync ServerReady, Log, Interrupt, Final IO] r => Sem r () Source #
Run the daemon API.
yank :: Members [Reader InstanceName, Client, ChronosTime, Log, Error Text, Embed IO] r => YankConfig -> Sem r () Source #
Send an event to the server.