diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-16 21:22:58 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-16 21:24:35 +0100 |
commit | 1e81fdf28bcd25c5fb1c2638b74ddb9d51bd5b72 (patch) | |
tree | 69038a6ec3a9f97433c83f2e25fbf7671eabada8 /src | |
parent | 3ba8a90c72c3dcc635eda57329d2dc6e950f9d2a (diff) | |
download | chawan-1e81fdf28bcd25c5fb1c2638b74ddb9d51bd5b72.tar.gz |
client, pager: various file saving fixes
* do not immediately quit when all containers are gone * fix double saving bug * fix wrong "save to" string
Diffstat (limited to 'src')
-rw-r--r-- | src/local/client.nim | 4 | ||||
-rw-r--r-- | src/local/pager.nim | 32 | ||||
-rw-r--r-- | src/local/term.nim | 4 |
3 files changed, 22 insertions, 18 deletions
diff --git a/src/local/client.nim b/src/local/client.nim index 87defeb4..5c93e375 100644 --- a/src/local/client.nim +++ b/src/local/client.nim @@ -643,8 +643,10 @@ proc inputLoop(client: Client) = client.command(client.pager.scommand) client.pager.scommand = "" client.handlePagerEvents() - if client.pager.container == nil: + if client.pager.container == nil and client.pager.lineedit.isNone: # No buffer to display. + client.pager.term.setCursor(0, client.pager.term.attrs.height - 1) + client.pager.term.anyKey("Hit any key to quit Chawan:") quit(1) client.pager.showAlerts() client.pager.draw() diff --git a/src/local/pager.nim b/src/local/pager.nim index 9ad854c4..6d748992 100644 --- a/src/local/pager.nim +++ b/src/local/pager.nim @@ -63,7 +63,7 @@ type lmISearchF = "/" lmISearchB = "?" lmGotoLine = "Goto line: " - lmDownload = "(Download) Save file to" + lmDownload = "(Download) Save file to: " # fdin is the original fd; fdout may be the same, or different if mailcap # is used. @@ -467,14 +467,14 @@ proc redraw(pager: Pager) {.jsfunc.} = proc draw*(pager: Pager) = let container = pager.container - if container == nil: return pager.term.hideCursor() - if pager.redraw: - pager.refreshDisplay() - pager.term.writeGrid(pager.display) - if container.select.open and container.select.redraw: - container.select.drawSelect(pager.display) - pager.term.writeGrid(pager.display) + if container != nil: + if pager.redraw: + pager.refreshDisplay() + pager.term.writeGrid(pager.display) + if container.select.open and container.select.redraw: + container.select.drawSelect(pager.display) + pager.term.writeGrid(pager.display) if pager.askpromise != nil or pager.askcharpromise != nil: discard elif pager.lineedit.isSome: @@ -488,11 +488,12 @@ proc draw*(pager: Pager) = pager.term.setCursor(pager.askcursor, pager.attrs.height - 1) elif pager.lineedit.isSome: pager.term.setCursor(pager.lineedit.get.getCursorX(), pager.attrs.height - 1) - elif container.select.open: - pager.term.setCursor(container.select.getCursorX(), - container.select.getCursorY()) - else: - pager.term.setCursor(pager.container.acursorx, pager.container.acursory) + elif container != nil: + if container.select.open: + pager.term.setCursor(container.select.getCursorX(), + container.select.getCursorY()) + else: + pager.term.setCursor(pager.container.acursorx, pager.container.acursory) pager.term.showCursor() pager.term.flush() pager.redraw = false @@ -1144,7 +1145,7 @@ proc saveTo(pager: Pager; data: LineDataDownload; path: string) = data.stream.close() pager.lineData = nil else: - pager.ask("Failed to save to path " & path & ". Retry?").then( + pager.ask("Failed to save to " & path & ". Retry?").then( proc(x: bool) = if x: pager.setLineEdit(lmDownload, path) @@ -1200,7 +1201,8 @@ proc updateReadLine*(pager: Pager) = else: pager.setLineEdit(lmDownload, lineedit.news) ) - pager.saveTo(data, lineedit.news) + else: + pager.saveTo(data, lineedit.news) of lmISearchF, lmISearchB: discard of lesCancel: case pager.linemode diff --git a/src/local/term.nim b/src/local/term.nim index 050edf3b..ffba3f1f 100644 --- a/src/local/term.nim +++ b/src/local/term.nim @@ -197,9 +197,9 @@ proc isatty*(f: File): bool = proc isatty*(term: Terminal): bool = term.infile != nil and term.infile.isatty() and term.outfile.isatty() -proc anyKey*(term: Terminal) = +proc anyKey*(term: Terminal; msg = "[Hit any key]") = if term.isatty(): - term.outfile.write("[Hit any key]") + term.outfile.write(term.clearEnd() & msg) discard term.infile.readChar() proc resetFormat(term: Terminal): string = |