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

pane:get_current_working_dir returns url encoded text for non-ascii paths #4000

Closed
hitobashira opened this issue Jul 15, 2023 · 5 comments
Closed
Labels
enhancement New feature or request fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.

Comments

@hitobashira
Copy link

hitobashira commented Jul 15, 2023

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

Linux X11

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

OS: Manjaro Linux x86_64
DE: Cinnamon
WM: Mutter (Muffin)

WezTerm version

wezterm 20230408-112425-69ae8472

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

No, and I'll explain why below

Describe the bug

valid character display.

It's been the same since I started using Wezterm. Any version.
I'm not in any trouble.

However, I would be happy to get a correctly encoded string.

Please let me know if there is any problem with my settings.

It's a low priority for me personally.

thank you.
2023-07-15_17-06

$ mkdir '日本語文字列(multibytes)' && cd $_ mkdir: ディレクトリ '日本語文字列(multibytes)' を作成しました /tmp/RAMRAM/WORKING/日本語文字列(multibytes) zish 2023-07-15 17:03:20 /tmp/RAMRAM/WORKING/日本語文字列(multibytes)

To Reproduce

No response

Configuration

local wezterm = require 'wezterm'
local mux = wezterm.mux
-- wezterm show-keys --lua

wezterm.on('gui-startup', function(cmd)
  local tab, pane, window = mux.spawn_window(cmd or {})
  -- 分割左右
  -- pane:split { direction = 'Bottom', size = 0.2,top_level = true }
  pane:split { direction = 'Bottom', size = 0.05 }
  pane:split { size = 0.5 }
  pane:split { direction = 'Bottom', size = 0.2 }
  pane:split { size = 0.5 }
  -- pane:split { size = 0.7 }

end)


-- ME 右ステータス
wezterm.on('update-status', function(window, pane)

-- How many lines of scrollback you want to retain per tab
-- config.scrollback_lines = 88888 勘違いしているな、me

  -- wezterm.on('update-right-status', function(window, pane) #ME OLD syntax
  -- Each element holds the text for a cell in a "powerline" style << fade
local cells = {}
-- Figure out the cwd and host of the current pane.
-- This will pick up the hostname for the remote host if your
-- shell is using OSC 7 on the remote host.
local cwd_uri = pane:get_current_working_dir()
if cwd_uri then
  cwd_uri = cwd_uri:sub(8)
  local slash = cwd_uri:find '/'
  local cwd = ''
  local hostname = ''
  if slash then
    hostname = cwd_uri:sub(1, slash - 1)
    -- Remove the domain name portion of the hostname
    local dot = hostname:find '[.]'
    if dot then
      hostname = hostname:sub(1, dot - 1)
    end
    -- and extract the cwd from the uri
    cwd = cwd_uri:sub(slash)

    table.insert(cells, cwd)
    table.insert(cells, hostname) -- 外してみた。2023年2月20日
  end
end

  local date = wezterm.strftime '%Y %B %-d %A %H:%M.%S'
  table.insert(cells, date)

  -- An entry for each battery (typically 0 or 1 battery)
  for _, b in ipairs(wezterm.battery_info()) do
    table.insert(cells, string.format('%.0f%%', b.state_of_charge * 100))
  end

  -- The powerline < symbol
  local LEFT_ARROW = utf8.char(0xe0b3)
  -- The filled in variant of the < symbol
  local SOLID_LEFT_ARROW = utf8.char(0xe0b2)

  -- Color palette for the backgrounds of each cell
  local colors = {
    '#3c1361',
    '#52307c',
    '#663a82',
    '#7c5295',
    '#b491c8',
  }

  -- Foreground color for the text across the fade
  -- local text_fg = '#e17e05'
  local text_fg = '#c0c0c0'

  -- The elements to be formatted
  local elements = {}
  -- How many cells have been formatted
  local num_cells = 0

  -- Translate a cell into elements
  function push(text, is_last)
    local cell_no = num_cells  + 1
    table.insert(elements, { Foreground = { Color = text_fg } })
    table.insert(elements, { Background = { Color = colors[cell_no] } })
    table.insert(elements, { Text = ' ' .. text .. ' ' })
    if not is_last then
      table.insert(elements, { Foreground = { Color = colors[cell_no + 1] } })
      table.insert(elements, { Text = SOLID_LEFT_ARROW })
    end
    num_cells = num_cells + 1
  end

  while #cells > 0 do
    local cell = table.remove(cells, 1)
    push(cell, #cells == 0)
  end

  window:set_right_status(wezterm.format(elements))
end)
-- -- ME




-- ME  タイトル
wezterm.on('format-window-title', function(tab, pane, tabs, panes, config)

  local zoomed = 'Wez🐰'
  if tab.active_pane.is_zoomed then
    -- zoomed = 'zzzConfig '
    zoomed = '[Z] '
  end

  local index = 'Term ' -- #ME うさぎの後ろ
  if #tabs > 1 then
    -- index = string.format('Wez.tabs ', tab.tab_index + 1, #tabs)
    index = string.format('[%d/%d] ', tab.tab_index + 1, #tabs)
  end

  return zoomed .. index .. tab.active_pane.title
end)


-- ME 色々設定はリターンの中でだいたいいける。
return {
-- ME いか2行いるのかな??
  -- use_ime = true,
  -- ime_preedit_rendering = "Builtin",


  -- Enable the scrollbar.
  -- It will occupy the right window padding space.
  -- If right padding is set to 0 then it will be increased
  -- to a single cell width
  enable_scroll_bar = true,
  tab_bar_at_bottom = false, -- ME 底にバー true,false
    window_decorations = "TITLE | RESIZE",
    default_prog = {"/bin/bash"}, -- ME デフォは -l ログインシェル扱いになる。ようになった2022-11-25気づき
    -- font = wezterm.font("PlemolJP Console NF Medium"), -- フォント
    font = wezterm.font( "HackGen35 Console NF" ), -- フォント
    font = wezterm.font_with_fallback({ "HackGen35 Console NF","Blobmoji",
    assume_emoji_presentation = true,}),
    font_size = 18.0,
    line_height = 1.25,
    cell_width = 0.85,
    initial_cols = 230,
    initial_rows = 50,
    freetype_load_target = 'Light',
    freetype_render_target = 'HorizontalLcd',
    freetype_load_flags = 'FORCE_AUTOHINT|MONOCHROME',
    color_scheme = "OneHalfDark", -- ME cf テーマ https://wezfurlong.org/wezterm/colorschemes/index.html
    hide_tab_bar_if_only_one_tab = false, -- 常時タブ表示
    adjust_window_size_when_changing_font_size = false,
    enable_scroll_bar = true,
    -- default_cwd = "/home/Running/"
    -- default_cwd = "$(echo $PWD)"
    -- default_cwd = "/home/zish/.config/wezterm/"
    window_background_opacity = 1.0,  -- ME 透明度    -- text_background_opacity = 0.8, -- ME テキスト不透明度 微妙
    window_frame = {
      -- The font used in the tab bar.
      -- Roboto Bold is the default; this font is bundled
      -- with wezterm.
      -- Whatever font is selected here, it will have the
      -- main font setting appended to it to pick up any
      -- fallback fonts you may have used there.
      -- font = wezterm.font { family = "PlemolJP Console NF Medium", weight = 'Bold' },
      font = wezterm.font { family = "HackGen35 Console NF", weight = 'Bold', },

      -- The size of the font in the tab bar.
      -- Default to 10. on Windows but 12.0 on other systems
      font_size = 15.0, -- ME BAR FONT
      -- The overall background color of the tab bar when
      -- the window is focused
      -- active_titlebar_fg = 'red',
      active_titlebar_bg = 'darkslateblue',

      -- The overall background color of the tab bar when
      -- the window is not focused
      inactive_titlebar_bg = '#333333',
      -- inactive_titlebar_bg = 'orange',
    },
    colors = {
      tab_bar = {
        -- The color of the inactive tab bar edge/divider
        inactive_tab_edge = 'darkslateblue',
        -- inactive_tab_edge = '#575757',
      },
    },




    -- disable_default_key_bindings = true,  -- ME デフォルトの割り当てを登録したくない場合は、この構成ですべてを無効にすることができます。すべてのバインディングを明示的に登録する必要があります。
    -- leader = { key = 'a', mods = 'SUPER', timeout_milliseconds = 1000 },
    keys = {
      { key = 'F11', mods = 'NONE'          ,action = wezterm.action.ToggleFullScreen, }, -- ME トグルフルスクリーン
      { key = 'F2',  mods = 'SHIFT'     ,action = wezterm.action.SplitVertical    { domain = 'CurrentPaneDomain' },}, -- me 分割 TMUX互換
      { key = 'F2',  mods = 'CTRL'      ,action = wezterm.action.SplitHorizontal  { domain = 'CurrentPaneDomain' },}, -- me 分割 TMUX互換
      { key = '=',   mods = 'ALT|SHIFT' ,action = wezterm.action.SplitVertical    { domain = 'CurrentPaneDomain' },}, -- ME 分割 独自
      { key = '|',   mods = 'ALT|SHIFT' ,action = wezterm.action.SplitHorizontal  { domain = 'CurrentPaneDomain' },}, -- ME 分割 独自
      {key="c", mods="SUPER", action=wezterm.action{CopyTo="Clipboard"}},
      {key="v", mods="SUPER", action=wezterm.action{PasteFrom="Clipboard"}},
      {key="t", mods="SUPER", action=wezterm.action{SpawnTab="CurrentPaneDomain"}},
        { key = 'l', mods = 'ALT', action = wezterm.action.ShowLauncher },
        { key = 'l', mods = 'CTRL|SHIFT',  action = wezterm.action.ShowLauncherArgs { flags = 'FUZZY|TABS' },   }, -- me /、ファジー フィルタリング モード
      -- {key="w", mods="CMD", action=wezterm.action{CloseCurrentTab={confirm=true}}}, -- 現在のタブを閉じる、閉じるときに確認をする
      -- {key="[", mods="CTRL", action=wezterm.action{ActivateTabRelative=-1}},
      -- {key="]", mods="CTRL", action=wezterm.action{ActivateTabRelative=1}},
      -- {key="{", mods="CTRL|SHIFT", action=wezterm.action{MoveTabRelative=-1}}, -- CTRL+SHIFT+[
      -- {key="}", mods="CTRL|SHIFT", action=wezterm.action{MoveTabRelative=1}}, -- CTRL+SHIFT+]
      -- {key="|", mods="CTRL|SHIFT", action=wezterm.action{SplitHorizontal={domain="CurrentPaneDomain"}}},
      -- {key="_", mods="CTRL|SHIFT", action=wezterm.action{SplitVertical={domain="CurrentPaneDomain"}}},
      -- {key="+", mods="CMD|SHIFT", action="IncreaseFontSize"},
      -- {key="_", mods="CMD|SHIFT", action="DecreaseFontSize"},

},

-- launch_menu nazo


    colors = {
      -- The default text color
      foreground = 'silver',
      -- The default background color
      background = '#00263E',

      -- Overrides the cell background color when the current cell is occupied by the
      -- cursor and the cursor style is set to Block
      cursor_bg = '#52ad70',
      -- Overrides the text color when the current cell is occupied by the cursor
      cursor_fg = 'black',
      -- Specifies the border color of the cursor when the cursor style is set to Block,
      -- or the color of the vertical or horizontal bar when the cursor style is set to
      -- Bar or Underline.
      cursor_border = '#52ad70',

      -- the foreground color of selected text
      selection_fg = 'silver',
      -- the background color of selected text
      -- selection_bg = '#fffacd',
      -- selection_bg = 'fuchsia',
      selection_bg = '#3e0354',

      -- The color of the scrollbar "thumb"; the portion that represents the current viewport
      -- scrollbar_thumb = '#222222',
      scrollbar_thumb = 'purple',

      -- The color of the split lines between panes
      split = '#666444',

      ansi = {
        'black',
        '#c8b328',
        'aquamarine',
        'olive',
        'skyblue',
        'orchid',
        'khaki',
        'silver',
      },
      brights = {
        'grey',
        'pink',
        'lime',
        'yellow',
        '#5d5dfd',
        'fuchsia',
        'aqua',
        'white',
      },

      -- Arbitrary colors of the palette in the range from 16 to 255
      indexed = { [136] = '#af8700' },

      -- Since: 20220319-142410-0fcdea07
      -- When the IME, a dead key or a leader key are being processed and are effectively
      -- holding input pending the result of input composition, change the cursor
      -- to this color to give a visual cue about the compose state.
      compose_cursor = 'orange',

      -- Colors for copy_mode and quick_select
      -- available since: 20220807-113146-c2fee766
      -- In copy_mode, the color of the active text is:
      -- 1. copy_mode_active_highlight_* if additional text was selected using the mouse
      -- 2. selection_* otherwise
      copy_mode_active_highlight_bg = { Color = '#000000' },
      -- use `AnsiColor` to specify one of the ansi color palette values
      -- (index 0-15) using one of the names "Black", "Maroon", "Green",
      --  "Olive", "Navy", "Purple", "Teal", "Silver", "Grey", "Red", "Lime",
      -- "Yellow", "Blue", "Fuchsia", "Aqua" or "White".
      copy_mode_active_highlight_fg = { AnsiColor = 'Black' },
      copy_mode_inactive_highlight_bg = { Color = '#52ad70' },
      copy_mode_inactive_highlight_fg = { AnsiColor = 'White' },

      quick_select_label_bg = { Color = '#D62598' },
      quick_select_label_fg = { Color = '#ffffff' },
      quick_select_match_bg = { Color = '#F8485E' },
      quick_select_match_fg = { Color = '#ffffff' },
    },
}

Expected Behavior

No response

Logs

No response

Anything else?

No response

@hitobashira hitobashira added the bug Something isn't working label Jul 15, 2023
@0f-0b
Copy link
Contributor

0f-0b commented Jul 15, 2023

pane:get_current_working_dir returns a file URI in which the path component is percent-encoded. You need to decode it before passing it to window:set_right_status.

@@ -41,7 +41,9 @@
       hostname = hostname:sub(1, dot - 1)
     end
     -- and extract the cwd from the uri
-    cwd = cwd_uri:sub(slash)
+    cwd = cwd_uri:sub(slash):gsub("%%(%x%x)", function(hex)
+      return string.char(tonumber(hex, 16))
+    end)
 
     table.insert(cells, cwd)
     table.insert(cells, hostname) -- 外してみた。2023年2月20日

@wez wez changed the title Wide character encode, eg Japanese. pane:get_current_working_dir returns url encoded text for non-ascii paths Jul 15, 2023
@hitobashira
Copy link
Author

0f-0b, wez.
Great. thanks.

@wez
Copy link
Owner

wez commented Jul 16, 2023

I've looked into this a bit and my conclusion is:

  • This isn't a bug pane:get_current_working_dir returns a URI string and the result is conformant with that
  • I do think it is a bit of a rough edge that the simple string manipulation on its own is not sufficient to produce a human readable version of the path
  • I think perhaps the way forward is to change that lua function to return a Url object that provides a convenience method to extract the path portion
  • There's a backwards compatibility concern to deal with; if we start return a Url object, the string manipulation that you and others are currently doing will break, so I'll need to give that some thought.

In the meantime, I'm reclassifying this as an enhancement issue to make it simpler to do the things that most people will want to do with that url.

@wez wez added enhancement New feature or request and removed bug Something isn't working labels Jul 16, 2023
wez added a commit that referenced this issue Aug 25, 2023
Previously we'd return the Url string.  Now we provide a Url
object that provides access to the various elements of the Url.

This will cause slightly breakage for folks that were treating
it as a string in their status event handlers, for example.

The docs have been updated to show how to run with both this
new Url object and also continue to run on older versions of
wezterm.

They now also show how to manually percent decode the url
for older versions of wezterm.

refs: #4157
refs: #4000
@wez
Copy link
Owner

wez commented Aug 25, 2023

In main, this method returns a Url object.
Please see the updated example on:

https://github.com/wez/wezterm/blob/b904ed7677aae82e185c63113f5d87df6edeef63/docs/config/lua/window/set_right_status.md

The Url object is documented at https://github.com/wez/wezterm/blob/b904ed7677aae82e185c63113f5d87df6edeef63/docs/config/lua/wezterm.url/Url.md

(those docs will show up on the website within 20-60 minutes)

It typically takes about an hour before commits are available as nightly builds for all platforms. Linux builds are the fastest to build and are often available within about 20 minutes. Windows and macOS builds take a bit longer.

Please take a few moments to try out the changes and let me know how that works out. You can find the nightly downloads for your system in the wezterm installation docs.

If you prefer to use packages provided by your distribution or package manager of choice and don't want to replace that with a nightly download, keep in mind that you can download portable packages (eg: a .dmg file on macOS, a .zip file on Windows and an .AppImage file on Linux) that can be run without permanently installing or replacing an existing package, and can then simply be deleted once you no longer need them.

If you are eager and can build from source then you may be able to try this out more quickly.

@wez wez added the fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds. label Aug 25, 2023
@wez wez closed this as completed Jan 27, 2024
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2024
ryusei1068 referenced this issue in ryusei1068/wezterm-conf Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request fixed-in-nightly This is (or is assumed to be) fixed in the nightly builds.
Projects
None yet
Development

No branches or pull requests

3 participants