Haskell 在分隔符内使用颜色| xmobar命令字段的固定宽度
我有一些xmobarrc配置Haskell 在分隔符内使用颜色| xmobar命令字段的固定宽度,haskell,xmonad,xmobar,Haskell,Xmonad,Xmobar,我有一些xmobarrc配置 Config { lowerOnStart = False, font = "xft:Terminus-12" , bgColor = "#000000" , fgColor = "#8080A1" , position = Top , commands = [ Run Network "eth0" ["-L","0","-H","32","--normal","#429942","--
Config { lowerOnStart = False,
font = "xft:Terminus-12"
, bgColor = "#000000"
, fgColor = "#8080A1"
, position = Top
, commands = [ Run Network "eth0" ["-L","0","-H","32","--normal","#429942","--high","#A36666"] 10
, Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run Memory ["-t","Mem: <usedratio>%"] 10
, Run Date "/%a/ %_d.%m.%Y / %H:%M" "date" 10
, Run Com "sh" ["~/bin/weather.sh"] "weather" 60
, Run StdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = " %StdinReader% }{ W:<fc=#fce94f>%weather%</fc> | %cpu% | %memory% | %eth0% | %date%"
}
Config{lowerOnStart=False,
font=“xft:终点站-12”
,bgColor=“#000000”
,fgColor=“#8080A1”
,位置=顶部
,命令=[运行网络“eth0”[“-L”、“0”、“-H”、“32”、“--normal”、“#429942”、“--high”、“#A36666”]10
,运行Cpu[“-L”,“3”,“-H”,“50”,“正常”,“绿色”,“高”,“红色”]10
,运行内存[“-t”,“内存:%”10
,运行日期“/%a/%u d.%m.%Y/%H:%m”“日期”10
,运行Com“sh”[“~/bin/weather.sh”]“weather”60
,运行StdinReader
]
,sepChar=“%”
,alignSep=“}{”
,template=“%StdinReader%}{W:%weather%|%cpu%|%memory%|%eth0%|%date%”
}
我有两个问题:
- 如果我需要一个着色分隔符
应在上更改所有的
例如,|
。所以 如何使用变量|
分隔符= |
模板中的
- 文本,即
和网络
回归,总会有不同的感觉 长度,所以所有笔划都有不同的 大小的所有时间。我该怎么设置Cpu
的文本是否为固定大小网络
intersperse separator
和concat
:
let temp = [" %StdinReader% }{ W:<fc=#fce94f>%weather%</fc> ", " %cpu% "," %memory% ", " %eth0% ", " %date%"]
separator = "<fc=#ffffff>|</fc>"
in concat $ Data.List.intersperse separator temp
对于第一个问题: 托马斯的回答似乎是可行的,但事实并非如此。xmobarrc文件语法看起来像Haskell,但实际上它对格式的限制非常严格,除了文件中已有的语法外,它不支持任何Haskell语法 这就是说,显而易见的答案是只需分别给它们上色。结果是一个模板行比它可能应该的长一点,也不太美观,以后修改它需要更多的工作,但老实说,只有四个
字符,所以它并没有那么糟糕
一个更好的解决方案是设置fgColor=“#ffffff”
,然后将“--low”、“#8080A1”
添加到每个命令的选项列表中,并将%StdinReader%
和%date%
包装在
中。基本上,将默认颜色设置为|
颜色,并显式为其他所有颜色。这样,就避免了编写所有那些fc
标记,因为这种颜色是隐式的。但我不建议这样做,因为这样会降低文件的清晰度
现在,实际上有一个更好的方法来解决这个问题和所有相关的问题:用真实的Haskell编写。您要做的是,编写一个Haskell程序,最终构建并格式化正确的xmobarrc,然后将其打印到文件中。我个人认为这对于任何恼人的配置文件来说都是一个很好的选择,但是xmobarrc是一个特别好的选择,因为它的语法非常接近Haskell。更具体地说,xmobarrc所使用的语法完全是Haskell用来描述文字数据的语法,这意味着我们所要做的就是构建一个Config
对象并运行它的默认show
,剩下的所有工作都是为我们完成的,除了一些微小的差异。事实上,在这里,我会很快为你写下这个。现在,如果导入该文件,并定义一个主文件,如下所示:
module Main (main) where
import XMobarHs
main = export $ config
{ lowerOnStart = False
, font = "xft:Terminus-12"
, bgColor = "#000000"
, fgColor = "#8080A1"
, position = Top
, commands = [ Run $ Network "eth0" ["-L","0","-H","32","--normal","#429942","--high","#A36666"] 10
, Run $ Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run $ Memory ["-t","Mem: <usedratio>%"] 10
, Run $ Date "/%a/ %_d.%m.%Y / %H:%M" "date" 10
, Run $ Com "sh" ["~/bin/weather.sh"] "weather" 60
, Run $ StdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = " %StdinReader% }{ W:<fc=#fce94f>%weather%</fc> | %cpu% | %memory% | %eth0% | %date%"
}
主模块(Main),其中
导入XMobarHs
main=export$config
{lowerOnStart=False
,font=“xft:Terminus-12”
,bgColor=“#000000”
,fgColor=“#8080A1”
,位置=顶部
,commands=[Run$Network“eth0”[“-L”、“0”、“-H”、“32”、“--normal”、“#429942”、“--high”、“#A36666”]10
,运行$Cpu[“-L”,“3”,“-H”,“50”,“--normal”,“green”,“--high”,“red”]10
,运行$Memory[“-t”,“Mem:%”10
,运行$Date/%a/%u d.%m.%Y/%H:%m“日期”10
,运行$Com“sh”[“~/bin/weather.sh”]“weather”60
,运行$StdinReader
]
,sepChar=“%”
,alignSep=“}{”
,template=“%StdinReader%}{W:%weather%|%cpu%|%memory%|%eth0%|%date%”
}
几乎完全一样。但也不一定是这样,因为现在是哈斯克尔,所以你实际上可以使用托马斯的想法,或者更进一步,达到你认为最好的程度。唯一的缺点是,每次编辑文件时,都必须编译并再次运行它,以获得更新的xmobarrc
关于第二个问题:
在命令的选项列表中,添加
“-w”,“3”
,将3替换为您希望命令字段固定的大小(字符数)。如果字段超过该大小,这将截断该字段,如果字段低于该大小,则用空格填充该字段。如果要用0(或其他字符)而不是空格填充,请同时添加“-c”,“0”
(或“-c”,“n”
,将n替换为要填充的字符)。xmobar自此注释以来可能有很多版本,因此可能会有格式更改。我已经很长时间没有使用xmobarrc了。如果您遇到问题,那么我建议您打开一个新问题。我只是想,您可以将编译/运行xmobarrc生成器绑定到mod+q,并将其放在xmonad之前——重新编译/重新启动。这样你就不用担心了。
...
, template = myTemplate
}
module Main (main) where
import XMobarHs
main = export $ config
{ lowerOnStart = False
, font = "xft:Terminus-12"
, bgColor = "#000000"
, fgColor = "#8080A1"
, position = Top
, commands = [ Run $ Network "eth0" ["-L","0","-H","32","--normal","#429942","--high","#A36666"] 10
, Run $ Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run $ Memory ["-t","Mem: <usedratio>%"] 10
, Run $ Date "/%a/ %_d.%m.%Y / %H:%M" "date" 10
, Run $ Com "sh" ["~/bin/weather.sh"] "weather" 60
, Run $ StdinReader
]
, sepChar = "%"
, alignSep = "}{"
, template = " %StdinReader% }{ W:<fc=#fce94f>%weather%</fc> | %cpu% | %memory% | %eth0% | %date%"
}