From c270df01e7e53ac86d3e1b8e1fae20cb19d0f745 Mon Sep 17 00:00:00 2001 From: Glenn Date: Sun, 4 Aug 2024 23:50:42 +0200 Subject: [PATCH] refactor(file_system_manager): extract fzf display as two functions --- src/file_system_manager.cr | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/file_system_manager.cr b/src/file_system_manager.cr index 9dc003c..8b8c97c 100644 --- a/src/file_system_manager.cr +++ b/src/file_system_manager.cr @@ -88,7 +88,7 @@ module GX config_root.filesystems end - def choose_filesystem + def choose_filesystem : GX::Models::AbstractFilesystemConfig? names_display = {} of String => NamedTuple( filesystem: Models::AbstractFilesystemConfig, ansi_name: String) @@ -97,17 +97,8 @@ module GX return if config_root.nil? config_root.filesystems.each do |filesystem| - fs_str = filesystem.type.ljust(12, ' ') - - suffix = "" - suffix_ansi = "" - if filesystem.mounted? - suffix = "[open]" - suffix_ansi = "[#{"open".colorize(:green)}]" - end - - result_name = "#{fs_str} #{filesystem.name} #{suffix}".strip - ansi_name = "#{fs_str.colorize(:dark_gray)} #{filesystem.name} #{suffix_ansi}".strip + result_name = _fzf_plain_name(filesystem) + ansi_name = _fzf_ansi_name(filesystem) names_display[result_name] = { filesystem: filesystem, @@ -128,12 +119,18 @@ module GX selected_filesystem end - private def generate_display_name(filesystem : Models::AbstractFilesystemConfig) : String + private def _fzf_plain_name(filesystem : Models::AbstractFilesystemConfig) : String fs_str = filesystem.type.ljust(12, ' ') suffix = filesystem.mounted? ? "[open]" : "" "#{fs_str} #{filesystem.name} #{suffix}".strip end + private def _fzf_ansi_name(filesystem : Models::AbstractFilesystemConfig) : String + fs_str = filesystem.type.ljust(12, ' ').colorize(:dark_gray) + suffix = filesystem.mounted? ? "[#{"open".colorize(:green)}]" : "" + "#{fs_str} #{filesystem.name} #{suffix}".strip + end + private def graphical_environment? if ENV["DISPLAY"]? || ENV["WAYLAND_DISPLAY"]? return true