wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
16.9k stars 760 forks source link

Last line of semantic zone output not being returned in pane:get_text_from_semantic_zone(zone) #5346

Open mgpinf opened 5 months ago

mgpinf commented 5 months ago

What Operating System(s) are you seeing this problem on?

macOS

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

20240405-180910-cce0706b

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Last line of semantic zone output not being returned in pane:get_text_from_semantic_zone(zone). Rest of the content is present. Enabled shell integration and tried in both zsh and fish.

Tried running the following command:

image

Obtained output (from logs):

01:01:57.041  INFO   logging > lua: total 0
drwxr-xr-x  2 unbxd  staff    64B Apr 28 00:40 another_dir
drwxr-xr-x  2 unbxd  staff    64B Apr 28 00:41 another_dir_2
drwxr-xr-x  2 unbxd  staff    64B Apr 28 00:38 dir1
-rw-r--r--  1 unbxd  staff     0B Apr 28 00:38 file1

To Reproduce

Enable shell integration in zsh/fish. Add below config and try out

Configuration

{
  key = 'v',
  action = wezterm.action_callback(function(window, pane)
    local output_semantic_zones = pane:get_semantic_zones("Output")
    if #output_semantic_zones > 0 then
      local output_content
      for i = 1, #output_semantic_zones, 1 do
        output_content = pane:get_text_from_semantic_zone(output_semantic_zones[i])
        wezterm.log_info(output_content)
      end
    end
  end)
}

Expected Behavior

Expected output should include last line as well.

Logs

01:01:57.041  INFO   logging > lua: total 0
drwxr-xr-x  2 unbxd  staff    64B Apr 28 00:40 another_dir
drwxr-xr-x  2 unbxd  staff    64B Apr 28 00:41 another_dir_2
drwxr-xr-x  2 unbxd  staff    64B Apr 28 00:38 dir1
-rw-r--r--  1 unbxd  staff     0B Apr 28 00:38 file1

Anything else?

No response

piechologist commented 4 months ago

As a workaround, I've been using the following function ever since:

local function my_fixed_get_text_from_semantic_zone(pane, zone)
    -- Unfortunately, the function `get_text_from_semantic_zone(zone)` swallows the last line.
    -- So we need to get the region up to column 0 of the line that follows the zone.
    return pane:get_text_from_region(zone.start_x, zone.start_y, 0, zone.end_y + 1)
end

Then, you can call:

output_content = my_fixed_get_text_from_semantic_zone(pane, output_semantic_zones[i])