aboutsummaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-25 00:32:54 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-25 00:33:39 +0100
commitb086e346afeded51c94c9b77280dcea6f6b3ce8a (patch)
treee2fd9f29e77ab787f960bbd8ba190a14a6d5d7a0 /src/display
parent896489a6c500e28f13d0237ab691622cb5c5114f (diff)
downloadchawan-b086e346afeded51c94c9b77280dcea6f6b3ce8a.tar.gz
Buffer improvements
Diffstat (limited to 'src/display')
-rw-r--r--src/display/client.nim47
-rw-r--r--src/display/pager.nim4
2 files changed, 29 insertions, 22 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index bd7f3977..f4acaee4 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -242,26 +242,31 @@ proc inputLoop(client: Client) =
client.acceptBuffers()
let events = client.selector.select(-1)
for event in events:
- if event.fd == client.console.tty.getFileHandle():
- client.input()
- stdout.flushFile()
- elif event.fd in client.interval_fdis:
- client.intervals[client.interval_fdis[event.fd]].handler()
- elif event.fd in client.timeout_fdis:
- let id = client.timeout_fdis[event.fd]
- let timeout = client.timeouts[id]
- timeout.handler()
- client.clearTimeout(id)
- elif event.fd == sigwinch:
- client.attrs = getWindowAttributes(client.console.tty)
- client.pager.windowChange(client.attrs)
- else:
- let container = client.fdmap[event.fd]
- if not client.pager.handleEvent(container):
- disableRawMode()
- for msg in client.pager.status:
- eprint msg
- client.quit(1)
+ if Read in event.events:
+ if event.fd == client.console.tty.getFileHandle():
+ client.input()
+ stdout.flushFile()
+ elif event.fd in client.interval_fdis:
+ client.intervals[client.interval_fdis[event.fd]].handler()
+ elif event.fd in client.timeout_fdis:
+ let id = client.timeout_fdis[event.fd]
+ let timeout = client.timeouts[id]
+ timeout.handler()
+ client.clearTimeout(id)
+ elif event.fd == sigwinch:
+ client.attrs = getWindowAttributes(client.console.tty)
+ client.pager.windowChange(client.attrs)
+ else:
+ let container = client.fdmap[event.fd]
+ if not client.pager.handleEvent(container):
+ disableRawMode()
+ for msg in client.pager.status:
+ eprint msg
+ client.quit(1)
+ elif Error in event.events:
+ eprint "Error", event
+ #TODO handle errors
+ else: assert false
if client.pager.scommand != "":
client.command(client.pager.scommand)
client.pager.scommand = ""
@@ -286,7 +291,6 @@ proc newConsole(pager: Pager, tty: File): Console =
raise newException(Defect, "Failed to open console pipe.")
let url = newURL("javascript:console.show()")
result.container = pager.readPipe0(some("text/plain"), pipefd[0], option(url))
- discard close(pipefd[0])
var f: File
if not open(f, pipefd[1], fmWrite):
raise newException(Defect, "Failed to open file for console pipe.")
@@ -333,7 +337,6 @@ proc launchClient*(client: Client, pages: seq[string], ctype: Option[string], du
client.userstyle = client.config.stylesheet.parseStylesheet()
if not stdin.isatty:
client.pager.readPipe(ctype, stdin.getFileHandle())
- stdin.close()
else:
client.console.tty = stdin
diff --git a/src/display/pager.nim b/src/display/pager.nim
index 3fdcd504..d04981a0 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -648,6 +648,10 @@ proc handleEvent*(pager: Pager, container: Container): bool =
pager.setLineEdit(readLine(event.prompt, pager.statusmsg.width, current = event.value, hide = event.password, config = pager.config, tty = pager.tty), BUFFER)
of OPEN:
pager.gotoURL(event.request, some(container.source.location))
+ of INVALID_COMMAND:
+ if container == pager.container:
+ if pager.status.len == 0:
+ pager.setStatusMessage("Invalid command from buffer")
of NO_EVENT: discard
return true