Skip to content

Conversation

@ilyagr
Copy link
Contributor

@ilyagr ilyagr commented Jul 5, 2024

This is WIP, but I'll put it here since it's:

  1. usable even if imperfect and
  2. might be worth discussing.

Now that borders and scroll bars are implemented, commands I use often wrap to the wrong number of columns. This has always been the case when the history window is open. This is because they get the full terminal width from the terminal and don't know that hwatch is using some columns for the UI.

There is, in fact, at least one standard way to address this: set the COLUMNS variable. Many programs, e.g. git diff --stat and Git in general, already support it.

COLUMNS is part of POSIX (apparently, the 2017 edition of the standard is freely available on that site).


My implementation works, but has one problem: COLUMNS is not set at the first program invocation, resulting in the user seeing a badly wrapped screen until the first update. Fixing this might require a bit of a refactor, I'm thinking about how best to do it.

A good way to test this is:

hwatch 'echo $COLUMNS $HWATCH_COLUMNS; git diff --stat master'

and then play with toggling UI/border/etc.

@ilyagr ilyagr changed the title Columns Export the current output width to watched program as COLUMNS environment variable Jul 5, 2024
@ilyagr
Copy link
Contributor Author

ilyagr commented Jul 5, 2024

It's also worth noting that there is a more heavy-weight potential solution of running the program in a pty, as in sachaos/viddy#8. However, I don't think that would work on Windows unless there's a cross-platform library.

Just for reference, https://github.com/Watfaq/PowerSession-rs probably includes similar functionality for Windows. However, somebody else would have to be interested in researching it further.

@ilyagr ilyagr force-pushed the columns branch 3 times, most recently from 68b4592 to 03a9111 Compare July 5, 2024 03:18
ilyagr added a commit to ilyagr/dotfiles that referenced this pull request Jul 8, 2024
@ilyagr ilyagr force-pushed the columns branch 4 times, most recently from f5fb20e to 86dfa3d Compare November 15, 2024 05:31
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

Successfully merging this pull request may close these issues.

1 participant