diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-07 16:10:18 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-07 16:10:18 +0200 |
commit | 93848e0c93ef0203393c48c8d9b48a2b51743107 (patch) | |
tree | 35113b8c73e831ab76d5de9bf7897857cdd8ce6a /src | |
parent | d78298ae3369374bf7bf31592513d112c75a9601 (diff) | |
download | chawan-93848e0c93ef0203393c48c8d9b48a2b51743107.tar.gz |
Add XTERM title renaming
Diffstat (limited to 'src')
-rw-r--r-- | src/buffer/container.nim | 4 | ||||
-rw-r--r-- | src/config/config.nim | 1 | ||||
-rw-r--r-- | src/display/pager.nim | 5 | ||||
-rw-r--r-- | src/display/term.nim | 48 |
4 files changed, 29 insertions, 29 deletions
diff --git a/src/buffer/container.nim b/src/buffer/container.nim index 7ee40f22..e301e05c 100644 --- a/src/buffer/container.nim +++ b/src/buffer/container.nim @@ -36,7 +36,7 @@ type ContainerEventType* = enum NO_EVENT, FAIL, SUCCESS, NEEDS_AUTH, REDIRECT, ANCHOR, NO_ANCHOR, UPDATE, - READ_LINE, READ_AREA, OPEN, INVALID_COMMAND, STATUS, ALERT, LOADED + READ_LINE, READ_AREA, OPEN, INVALID_COMMAND, STATUS, ALERT, LOADED, TITLE ContainerEvent* = object case t*: ContainerEventType @@ -679,7 +679,7 @@ proc onload(container: Container, res: LoadResult) = container.iface.getTitle().then(proc(title: string): auto = if title != "": container.title = title - container.triggerEvent(STATUS) + container.triggerEvent(TITLE) return container.iface.render() ).then(proc(lines: int): auto = container.setNumLines(lines, true) diff --git a/src/config/config.nim b/src/config/config.nim index 90402149..d242c37d 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -88,6 +88,7 @@ type double_width_ambiguous*: bool minimum_contrast*: int32 force_clear*: bool + set_title*: bool #TODO: add JS wrappers for objects Config* = ref ConfigObj diff --git a/src/display/pager.nim b/src/display/pager.nim index 85381c48..fde58c92 100644 --- a/src/display/pager.nim +++ b/src/display/pager.nim @@ -93,6 +93,7 @@ iterator containers*(pager: Pager): Container {.inline.} = proc setContainer*(pager: Pager, c: Container) {.jsfunc.} = pager.container = c pager.redraw = true + pager.term.setTitle(c.getTitle()) proc hasprop(pager: Pager, s: string): bool {.jshasprop.} = if pager.container != nil: @@ -854,6 +855,10 @@ proc handleEvent0(pager: Pager, container: Container, event: ContainerEvent): bo of STATUS: if pager.container == container: pager.refreshStatusMsg() + of TITLE: + if pager.container == container: + pager.refreshStatusMsg() + pager.term.setTitle(container.getTitle()) of ALERT: if pager.container == container: pager.alert(event.msg) diff --git a/src/display/term.nim b/src/display/term.nim index e665faee..4f33ee1a 100644 --- a/src/display/term.nim +++ b/src/display/term.nim @@ -61,35 +61,24 @@ func hascap(term: Terminal, c: TermcapCap): bool = term.tc.caps[c] != nil func cap(term: Terminal, c: TermcapCap): string = $term.tc.caps[c] func ccap(term: Terminal, c: TermcapCap): cstring = term.tc.caps[c] -template CSI*(s: varargs[string, `$`]): string = - var r = "\e[" - var first = true - for x in s: - if not first: - r &= ";" - first = false - r &= x - r +# control sequence introducer +template CSI(s: varargs[string, `$`]): string = + "\e[" & s.join(';') + +# OS command +template OSC(s: varargs[string, `$`]): string = + "\e]" & s.join(';') & '\a' + +template XTERM_TITLE(s: string): string = + OSC(0, s) when not termcap_found: + # DEC set template DECSET(s: varargs[string, `$`]): string = - var r = "\e[?" - var first = true - for x in s: - if not first: - r &= ";" - first = false - r &= x - r & "h" + "\e[?" & s.join(';') & 'h' + # DEC reset template DECRST(s: varargs[string, `$`]): string = - var r = "\e[?" - var first = true - for x in s: - if not first: - r &= ";" - first = false - r &= x - r & "l" + "\e[?" & s.join(';') & 'l' template SMCUP(): string = DECSET(1049) template RMCUP(): string = DECRST(1049) template HVP(s: varargs[string, `$`]): string = @@ -324,6 +313,10 @@ proc windowChange*(term: Terminal, attrs: WindowAttributes) = term.canvas = newFixedGrid(attrs.width, attrs.height) term.cleared = false +proc setTitle*(term: Terminal, title: string) = + if term.config.display.set_title: + term.outfile.write(XTERM_TITLE(title)) + proc processOutputString*(term: Terminal, str: string, w: var int): string = if str.validateUtf8() != -1: return "?" @@ -447,8 +440,9 @@ proc applyConfig(term: Terminal) = for fm in FormatFlags: if fm in term.config.display.no_format_mode: term.formatmode.excl(fm) - if term.isatty() and term.config.display.alt_screen.isSome: - term.smcup = term.config.display.alt_screen.get + if term.isatty(): + if term.config.display.alt_screen.isSome: + term.smcup = term.config.display.alt_screen.get term.mincontrast = term.config.display.minimum_contrast if term.config.encoding.display_charset.isSome: term.cs = term.config.encoding.display_charset.get |