Module: Charming::Controller::Terminal

Included in:
Charming::Controller
Defined in:
lib/charming/controller/terminal.rb

Overview

Terminal mixes imperative out-of-band terminal effects into Controller: writing the system clipboard, raising desktop notifications, ringing the bell, and setting the window title. Each registers an Escape sequence onto the dispatch's collection; the Runtime flushes it to the backend before the next frame. They compose freely with a normal render — e.g. def copy_url; copy(state.url); notify("Copied!"); render(:show); end.

Instance Method Summary collapse

Instance Method Details

#bellObject

Rings the terminal bell.



23
24
25
# File 'lib/charming/controller/terminal.rb', line 23

def bell
  Escape.register(Escape.bell)
end

#copy(text, target: "c") ⇒ Object

Writes text to the system clipboard (OSC 52). target selects the selection ("c" clipboard, "p" primary). Works across Ghostty/Kitty/iTerm2 (and tmux with passthrough).



13
14
15
# File 'lib/charming/controller/terminal.rb', line 13

def copy(text, target: "c")
  Escape.register(Escape.clipboard(text, target: target))
end

#notify(body, title: nil) ⇒ Object

Raises a desktop notification showing body (and title when given).



18
19
20
# File 'lib/charming/controller/terminal.rb', line 18

def notify(body, title: nil)
  Escape.register(Escape.notification(body, title: title))
end

#set_title(text) ⇒ Object

Sets the terminal window/tab title to text (OSC 0).



28
29
30
# File 'lib/charming/controller/terminal.rb', line 28

def set_title(text)
  Escape.register(Escape.title(text))
end