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

fix: defer setting 'columns' to hardwrap at 300 columns #267

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ local function get_scrollback_cmd(get_text_args)
return scrollback_cmd, full_cmd
end

local function defer_resize_term(min_cols)
local orig_columns = vim.o.columns
if vim.o.columns < min_cols then
vim.defer_fn(function()
vim.o.columns = min_cols
vim.api.nvim_set_option_value('columns', min_cols, { scope = 'global' })
end, 0)
end
return orig_columns
end

---@param get_text_opts KsbKittyGetTextArguments
---@param on_exit_cb function
M.get_text_term = function(get_text_opts, on_exit_cb)
Expand All @@ -60,9 +71,14 @@ M.get_text_term = function(get_text_opts, on_exit_cb)
local stderr
local tail_max = 10

-- increase the number of columns temporary so that the width is used during the
-- terminal command kitty @ get-text. this avoids hard wrapping lines to the
-- current window size. Note: a larger min_cols appears to impact performance
-- defer is used as a timing workaround because this is expected to be called right before termopen
p.orig_columns = defer_resize_term(300)

-- set the shell used for termopen to sh to avoid imcompatabiliies with other shells (e.g., nushell, fish, etc)
vim.o.shell = 'sh'

local success, error = pcall(vim.fn.termopen, full_cmd, {
stdout_buffered = true,
stderr_buffered = true,
Expand All @@ -73,6 +89,11 @@ M.get_text_term = function(get_text_opts, on_exit_cb)
stderr = data
end,
on_exit = function(id, exit_code, event)
-- NOTE(#58): nvim v0.9 support
-- vim.o.columns is resized automatically in nvim v0.9.1 when we trigger kitty so send a SIGWINCH signal
-- vim.o.columns is explicitly set to resize appropriatley on v0.9.0
-- see https://github.com/neovim/neovim/pull/23503
vim.o.columns = p.orig_columns
if exit_code == 0 then
-- no need to check allow_remote_control or dev/tty because earlier commands would have reported the error
if #stdout >= 2 then
Expand Down
14 changes: 0 additions & 14 deletions lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,22 +389,8 @@ M.launch = function()

ksb_autocmds.load_autocmds()

-- increase the number of columns temporary so that the width is used during the
-- terminal command kitty @ get-text. this avoids hard wrapping lines to the
-- current window size. Note: a larger min_cols appears to impact performance
local min_cols = 300
p.orig_columns = vim.o.columns
if vim.o.columns < min_cols then
vim.o.columns = min_cols
end
vim.schedule(function()
ksb_kitty_cmds.get_text_term(get_text_opts(), function()
-- NOTE(#58): nvim v0.9 support
-- vim.o.columns is resized automatically in nvim v0.9.1 when we trigger kitty so send a SIGWINCH signal
-- vim.o.columns is explicitly set to resize appropriatley on v0.9.0
-- see https://github.com/neovim/neovim/pull/23503
vim.o.columns = p.orig_columns

ksb_kitty_cmds.signal_winchanged_to_kitty_child_process()
if opts.kitty_get_text.extent == 'screen' or opts.kitty_get_text.extent == 'all' then
set_cursor_position(p.kitty_data)
Expand Down
44 changes: 22 additions & 22 deletions tests/bashrc
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# thanks https://github.com/kalgynirae/dotfiles/blob/1203030bd44448088c4c1a42155a254171a31c4b/bashrc#L59
# Test the terminal's text/color capabilities
colortest() {
local color escapes intensity style
echo "NORMAL bold dim itali under rever strik BRIGHT bold dim itali under rever strik"
for color in $(seq 0 7); do
for intensity in 3 9; do # normal, bright
escapes="${intensity}${color}"
printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$escapes" # normal
for style in 1 2 3 4 7 9; do # bold, dim, italic, underline, reverse, strikethrough
escapes="${intensity}${color};${style}"
printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$style"
done
echo -n " "
done
echo
done
echo -n "TRUECOLOR "
awk 'BEGIN{
local color escapes intensity style
echo "NORMAL bold dim itali under rever strik BRIGHT bold dim itali under rever strik"
for color in $(seq 0 7); do
for intensity in 3 9; do # normal, bright
escapes="${intensity}${color}"
printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$escapes" # normal
for style in 1 2 3 4 7 9; do # bold, dim, italic, underline, reverse, strikethrough
escapes="${intensity}${color};${style}"
printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$style"
done
echo -n " "
done
echo
done
echo -n "TRUECOLOR "
awk 'BEGIN{
columns = 78;
step = columns / 6;
for (hue = 0; hue<columns; hue++) {
Expand All @@ -43,17 +43,17 @@ colortest() {
}

banner() {
printf "\\033[0m\\033[38;2;167;192;128m"
cat <<EOF
printf "\\033[0m\\033[38;2;167;192;128m"
cat <<EOF
_ _ _____ _______ _______ __ __ _______ _______ ______ _____ ______ _______ _______ _ _ __ _ _ _ _____ _______
|____/ | | | \_/ ___ |______ | |_____/ | | | | |_____] |_____| | |____/ | \ | \ / | | | |
| \_ __|__ | | | ______| |_____ | \_ |_____| |_____ |_____ |_____] | | |_____ | \_ . | \_| \/ __|__ | | |
EOF
printf "\\033[0m\\n"
printf "\\033[0m\\n"
}

lolbanner() {
cat <<'EOF'
cat <<'EOF'
        _     _ _____ _______ _______ __   __     _______ _______  ______  _____                ______  _______ _______ _     _   __   _ _    _ _____ _______
        |____/    |      |       |      \_/   ___ |______ |       |_____/ |     | |      |      |_____] |_____| |       |____/    | \  |  \  /    |   |  |  |
        |    \_ __|__    |       |       |        ______| |_____  |    \_ |_____| |_____ |_____ |_____] |     | |_____  |    \_ . |  \_|   \/   __|__ |  |  |
Expand All @@ -62,7 +62,7 @@ EOF
}

ksb_tree() {
cat <<'EOF'
cat <<'EOF'
../kitty-scrollback.nvim/lua
└── kitty-scrollback
 ├── api.lua
Expand All @@ -88,7 +88,7 @@ EOF
}

loldino() {
cat <<'EOF'
cat <<'EOF'
 ______ 
( nice )
 ------ 
Expand Down
Loading
Loading