Git GUI 的暗色主题

8

几天前,我偶然看到了这张带有黑色主题的Git GUI图片。

enter image description here

我已经阅读了文档,搜索了菜单并询问了DuckDuckGo,但到目前为止我还没有弄清楚如何更改主题。怎么做呢? 编辑:我使用Ubuntu 16.04和一个暗色主题。Git gui完全忽略了我的DE的主题设置,因此我无法想象它与此有关,正如kowsky在下面建议的那样

我正在使用一个名为“真彩反转”的 Gnome 扩展 super+i 在单个窗口上。虽然不完美,但它可以避免刺眼的感觉。;) - Aquarius Power
4个回答

4

我猜你是从这里截取了那张图片?

发布这些截图的用户表示:

[...] 我正在使用深色主题的 Windows,[...]

并且

Git-GUI(主窗口)必须使用 Windows 本机颜色 [...]

因此,我怀疑他通过相应地设置默认的 Windows 颜色主题来实现了这个“深色主题”。


很抱歉,我没有提到我的系统 - 没有想到它可能会相关。 - Luís de Sousa
我也在使用暗黑模式的Windows。但是Git Gui仍然是白色的。 - SZT
对我来说也是一样,Windows 10 的暗黑模式似乎不会影响 git-gui 版本 0.21.GITGUI。 - David Bradley

3
这段文字的意思是:

目前有一个 GitHub 问题,正在开始为 Git GUI 开发“官方”暗黑模式。截至本文撰写时,当前的建议包括 编辑 git-gui.tcl 文件,在大约第869行的 pave_toplevel . 行后添加以下几行代码:

ttk::style theme use default
ttk::style configure TFrame -background #333
ttk::style configure TLabelframe -background #333
ttk::style configure TLabelframe.Label -background #333 -foreground #fff
ttk::style configure TPanedwindow  -background #333
ttk::style configure EntryFrame -background #333
ttk::style configure TScrollbar -background #666 -troughcolor #444 -arrowcolor #fff -arrowsize 15
ttk::style map TScrollbar -background [list active #333 disabled #000]
ttk::style configure TLabel -background #333 -foreground #fff
ttk::style configure TButton -background #333 -foreground #fff -borderwidth 2 -bordercolor #fff
ttk::style map TButton -background [list active #555 disabled #111 readonly #000]
ttk::style configure TCheckbutton -background #333 -foreground #fff -indicatorbackground #666 -indicatorcolor #fff
ttk::style map TCheckbutton -background [list active #555 disabled #111 readonly #000]
ttk::style configure TEntry -fieldbackground #333 -background #333 -foreground #fff -insertcolor #fff
ttk::style configure TRadiobutton -background #333 -foreground #fff
ttk::style map TRadiobutton -background [list active #555 disabled #111 readonly #000]
option add *TCombobox*Listbox.background #333 interactive
option add *TCombobox*Listbox.foreground #fff interactive
option add *TCombobox*Listbox.selectBackground blue interactive
option add *TCombobox*Listbox.selectForeground #fff interactive
option add *Listbox.Background #333 interactive
option add *Listbox.Foreground #fff interactive
option add *Text.Background #333 interactive
option add *Text.Foreground #fff interactive
ttk::style configure TSpinbox -fieldbackground #333 -background #333 -foreground #fff -insertcolor #fff -arrowcolor #fff \
    .vpane.lower.commarea.buffer.frame.t \
    configure -background #0d1117 -foreground #fff -insertbackground #fff \
    .vpane.lower.diff.body.t configure -background #0d1117 -foreground #fff \
    .vpane.files.workdir.list configure -background #0d1117 -foreground #fff \
    .vpane.files.index.list configure -background #0d1117 -foreground #fff \
    .about_dialog.git_logo configure -background #333

上述行将改变绝大多数事物。要调整部分的边框/轮廓,请在文件中更下方的“加载窗口状态”注释上方插入以下行:
.vpane.files.index.list configure -background #333 -highlightbackground #333 -highlightthickness 1
.vpane.files.workdir.list configure -background #333 -highlightbackground #333 -highlightthickness 1
.vpane.lower.diff.body.t configure -background #333 -highlightbackground #333 -highlightthickness 1
.vpane.lower.commarea.buffer.frame.t configure -background #333 -highlightbackground #333 -highlightthickness 1

顺便提一下,我在Windows上需要上面的内容。在Mac上,git gui似乎遵循系统主题 - 至少在来自brew的git版本2.32中是这样。


2

Plakhoy的答案展示了如何为选择仓库页面添加样式。要将应用程序的其余部分更改为深色模式,请按照以下建议进行操作。我没有足够的声望来发布图片,但您可以更改几行代码以启用Git Gui的暗模式。

这将创建一个黑色背景,并带有浅色(几乎白色)文本。

文件位置:C:\ Program Files \ Git \ mingw64 \ share \ git-gui \ lib \ themed.tcl

themed.tcl的14-20行是原始设置(亮色模式)。

proc sync_with_theme {} {  
    set base_bg             [ttk::style lookup . -background]  
    set base_fg             [ttk::style lookup . -foreground]  
    set text_bg             [ttk::style lookup Treeview -background]  
    set text_fg             [ttk::style lookup Treeview -foreground]  
    set select_bg           [ttk::style lookup Default -selectbackground]  
    set select_fg           [ttk::style lookup Default -selectforeground]  

在themed.tcl中,将第14-20行更改如下(深色模式)。

proc sync_with_theme {} {  
    set base_bg             #282a36  
    set base_fg             #f8f8f2  
    set text_bg             #282a36  
    set text_fg             #f8f8f2  
    set select_bg           #f8f8f2  
    set select_fg           #282a36

这部分获取了主窗口,但是诸如分支可视化之类的东西没有受到影响。可能需要对其他tcl文件进行一些额外的更改,也许是branch.tcl文件。 - David Bradley

1
颜色是硬编码的,定义在一个名为 choose_repository.tcl 的文件中。不确定 Ubuntu 是怎样的,但在 Windows 中它位于 C:\Program Files\Git\mingw64\share\git-gui\lib\choose_repository.tcl。将颜色更改为您喜欢的颜色。我的看起来像这样,使用此补丁:

Git Gui



@@ -91,17 +91,18 @@ constructor pick {} {
    ${NS}::frame $w_body
    text $opts \
        -cursor $::cursor_ptr \
        -relief flat \
        -background [get_bg_color $w_body] \
+       -foreground lime \
        -wrap none \
        -spacing1 5 \
        -width 50 \
        -height 3
    pack $opts -anchor w -fill x

-   $opts tag conf link_new -foreground blue -underline 1
+   $opts tag conf link_new -underline 1
    $opts tag bind link_new <1> [cb _next new]
    $opts insert end [mc "Create New Repository"] link_new
    $opts insert end "\n"
    if {$m_repo ne {}} {
        $m_repo add command \
@@ -110,11 +111,11 @@ constructor pick {} {
            -label [mc "New..."]
        bind $top <$M1B-n> [cb _next new]
        bind $top <$M1B-N> [cb _next new]
    }

-   $opts tag conf link_clone -foreground blue -underline 1
+   $opts tag conf link_clone -underline 1
    $opts tag bind link_clone <1> [cb _next clone]
    $opts insert end [mc "Clone Existing Repository"] link_clone
    $opts insert end "\n"
    if {$m_repo ne {}} {
        if {[tk windowingsystem] eq "win32"} {
@@ -128,11 +129,11 @@ constructor pick {} {
            -label [mc "Clone..."]
        bind $top <$M1B-[string tolower $key]> [cb _next clone]
        bind $top <$M1B-[string toupper $key]> [cb _next clone]
    }

-   $opts tag conf link_open -foreground blue -underline 1
+   $opts tag conf link_open -underline 1
    $opts tag bind link_open <1> [cb _next open]
    $opts insert end [mc "Open Existing Repository"] link_open
    $opts insert end "\n"
    if {$m_repo ne {}} {
        $m_repo add command \
@@ -169,12 +170,12 @@ constructor pick {} {
            -background [get_bg_color $w_body.recentlabel] \
            -wrap none \
            -width 50 \
            -height $lenrecent
        $w_recentlist tag conf link \
-           -foreground blue \
-           -underline 1
+           -foreground yellow \
+           -underline 0
        set home $::env(HOME)
        if {[is_Cygwin]} {
            set home [exec cygpath --windows --absolute $home]
        }
        set home "[file normalize $home]/"


2
也许它位于 /usr/share/git-gui/lib/choose_repository.tcl。至少,这是我的猜测。 - dan1st
看起来我们很接近了。不幸的是,这个补丁在 choose_repository.tcl 上失败了。这个文件可能在不同的版本中有所不同(我正在使用2.17.1)。你能提供一些更通用的东西吗? - Luís de Sousa
@LuísdeSousa,你找到那些行了吗?我添加了一个补丁,指向你需要更改的行。文件会随着时间的推移而改变,但相关部分应该仍然类似于此差异中的部分。 - Plakhoy
我手动应用了这些代码。现在启动屏幕上有几行以黄色呈现。除此之外,GUI看起来和以前一样。 - Luís de Sousa

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接