Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodic autorefresh of buffer visualization #69

Open
tom-adsfund opened this issue Sep 10, 2023 · 5 comments
Open

Periodic autorefresh of buffer visualization #69

tom-adsfund opened this issue Sep 10, 2023 · 5 comments

Comments

@tom-adsfund
Copy link

In my window manager, i3, the shape of the terminal changes over time, and so if I return to Liquid, it's all jumbled up. Can we just have a running autorefresh, or something similar?

@mogenslund
Copy link
Owner

I will give it at shot more, soon. As far as I remember it can be difficult to get information about the dimensions of the terminal on runtime. But I will give it another try :-)

@tom-adsfund
Copy link
Author

Wouldn't it be easiest to do a periodic refresh whatever happens? Maybe add a toggle to stop it if someone finds there's an issue?

@mogenslund
Copy link
Owner

Pressing ESC twice usually redraws everything, but it does not take into account, if the terminal has be resized. I will have to recalculate the size of each window. I think periodic refreshes will be a bit annoying since the user will experience a slight flicker when nothing is happening. But if I manage to create a good resize function, it should be possible to make a toggle on the periodic refresh.

@tom-adsfund
Copy link
Author

stty size gives the terminal size. Which you're actually using already in tty_output.cljc.

SIGWINCH process signal tells when the terminal has been resized. But Java only has a non-standard mechanism to get it:

; Nice GPT4o solution:
; (:import [sun.misc Signal SignalHandler])

(defn handle-sigwinch [ch]
  (reify SignalHandler
    (handle [_ signal]
      (let [[rows cols] (get-terminal-size)]
        (put! ch {:rows rows :cols cols})))))

(defn redraw-editor [rows cols]
  (println (str "Terminal resized to " rows " rows and " cols " columns")))

(defn main-loop []
  (let [sigwinch-chan (chan)]
    (Signal/handle (Signal. "WINCH") (handle-sigwinch sigwinch-chan))
    (go-loop []
      (let [{:keys [rows cols]} (<! sigwinch-chan)]
        (redraw-editor rows cols)
        (recur)))))

But you can at least hook in stty size to the ESC ESC, and maybe put on a toggleable timer.

@tom-adsfund
Copy link
Author

Also:

; (:require [clojure.java.shell :refer [sh]]
(defn get-terminal-size []
  (let [size (sh "stty" "size")]
    (mapv #(Integer/parseInt %) (re-seq #"\d+" (:out size)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants