From e7b6501dca34023a9d9be3751893eb927905ba4c Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 9 Apr 2022 00:58:47 +0300 Subject: [PATCH] feat(prog/xmonad): compile bar from haskell --- .gitignore | 3 - nix/home.nix | 7 +- programs/xmonad/xmobar.hs | 24 ----- programs/xmonad/xmobar/.gitignore | 2 + programs/xmonad/xmobar/README.md | 1 + programs/xmonad/xmobar/Setup.hs | 2 + programs/xmonad/xmobar/package.yaml | 21 ++++ programs/xmonad/xmobar/src/xmobar.hs | 137 +++++++++++++++++++++++++ programs/xmonad/xmobar/stack.yaml | 74 +++++++++++++ programs/xmonad/xmobar/stack.yaml.lock | 34 ++++++ programs/xmonad/xmobar/xmobarrc.cabal | 26 +++++ 11 files changed, 300 insertions(+), 31 deletions(-) delete mode 100644 programs/xmonad/xmobar.hs create mode 100644 programs/xmonad/xmobar/.gitignore create mode 100644 programs/xmonad/xmobar/README.md create mode 100644 programs/xmonad/xmobar/Setup.hs create mode 100644 programs/xmonad/xmobar/package.yaml create mode 100644 programs/xmonad/xmobar/src/xmobar.hs create mode 100644 programs/xmonad/xmobar/stack.yaml create mode 100644 programs/xmonad/xmobar/stack.yaml.lock create mode 100644 programs/xmonad/xmobar/xmobarrc.cabal diff --git a/.gitignore b/.gitignore index 41a281b..745d197 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,3 @@ !/programs -/programs/xmonad/* -!/programs/xmonad/*.hs - diff --git a/nix/home.nix b/nix/home.nix index 105c71f..b438af9 100644 --- a/nix/home.nix +++ b/nix/home.nix @@ -43,7 +43,6 @@ in home.packages = with pkgs; [ # system ui dmenu # menu for x window system - xmobar # a minimalistic text based status bar flameshot # powerful yet simple to use screenshot software # tools @@ -81,12 +80,12 @@ in SetPartialStrut = true; expand = true; transparent = true; - alpha = 50; + alpha = 0; edge = "top"; align = "right"; width = 4; - height = 24; - tint = "0x5f5f5f"; + height = 20; + tint = "0xff222222"; }; }; diff --git a/programs/xmonad/xmobar.hs b/programs/xmonad/xmobar.hs deleted file mode 100644 index 292558f..0000000 --- a/programs/xmonad/xmobar.hs +++ /dev/null @@ -1,24 +0,0 @@ -Config { overrideRedirect = False - , font = "xft:Fira Code:size=12:antialias=true" - , bgColor = "#5f5f5f" - , fgColor = "#f8f8f2" - , position = TopW L 96 - , commands = [ Run Cpu - [ "-L", "3" - , "-H", "50" - , "--high" , "red" - , "--normal", "green" - ] 10 - , Run Memory ["--template", "Mem: %"] 10 - , Run Swap [] 10 - , Run Date "%a %Y-%m-%d %H:%M" "date" 10 - , Run XMonadLog - , Run Kbd [("us(dvorak)", "us"), ("ru", "ru")] - , Run Wireless "" - [ "--template", "wlan " - ] 10 - ] - , sepChar = "%" - , alignSep = "}{" - , template = "%XMonadLog% }{ %cpu% | %memory% * %swap% %wi% | %kbd% | %date% " - } diff --git a/programs/xmonad/xmobar/.gitignore b/programs/xmonad/xmobar/.gitignore new file mode 100644 index 0000000..c368d45 --- /dev/null +++ b/programs/xmonad/xmobar/.gitignore @@ -0,0 +1,2 @@ +.stack-work/ +*~ \ No newline at end of file diff --git a/programs/xmonad/xmobar/README.md b/programs/xmonad/xmobar/README.md new file mode 100644 index 0000000..5e0b623 --- /dev/null +++ b/programs/xmonad/xmobar/README.md @@ -0,0 +1 @@ +# xmobar diff --git a/programs/xmonad/xmobar/Setup.hs b/programs/xmonad/xmobar/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/programs/xmonad/xmobar/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/programs/xmonad/xmobar/package.yaml b/programs/xmonad/xmobar/package.yaml new file mode 100644 index 0000000..295f36f --- /dev/null +++ b/programs/xmonad/xmobar/package.yaml @@ -0,0 +1,21 @@ +name: xmobarrc +version: 0.1.0 +synopsis: My xmobar configuration +license: Beerware +author: Pleshevskiy +maintainer: dmitriy@ideascup.me +homepage: https://github.com/pleshevskiy/myconfig + +dependencies: +- base +- xmobar + +executables: + xmobar: + source-dirs: src + main: xmobar.hs + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + diff --git a/programs/xmonad/xmobar/src/xmobar.hs b/programs/xmonad/xmobar/src/xmobar.hs new file mode 100644 index 0000000..b95e9ec --- /dev/null +++ b/programs/xmonad/xmobar/src/xmobar.hs @@ -0,0 +1,137 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE PostfixOperators #-} +{-# LANGUAGE ScopedTypeVariables #-} +------------------------------------------------------------------------------ +-- | +-- Copyright: (c) 2018, 2019, 2022 Jose Antonio Ortega Ruiz +-- License: BSD3-style (see LICENSE) +-- +-- Maintainer: jao@gnu.org +-- Stability: unstable +-- Portability: portable +-- Created: Sat Nov 24, 2018 21:03 +-- +-- +-- An example of a Haskell-based xmobar. Compile it with +-- ghc --make -- xmobar.hs +-- with the xmobar library installed or simply call: +-- xmobar /path/to/xmobar.hs +-- and xmobar will compile and launch it for you and +------------------------------------------------------------------------------ + +import Xmobar + +import System.Environment (getArgs) + +------------------------------------------------------------------------------ + +main :: IO () +main = getArgs >>= \case + ["-x", n] -> xmobar . config $ read n + _ -> xmobar . config $ 0 + +------------------------------------------------------------------------------ + +config :: Int -> Config +config n = defaultConfig + -- fonts + { font = regularFont 9 + , additionalFonts = + [ boldFont 9 + ] + + -- colors + , bgColor = colorBg + , fgColor = colorFg + + -- general + , position = OnScreen n (TopW L 96) + , overrideRedirect = False + , commands = myCommands + , sepChar = "%" + , alignSep = "}{" + , template = "%XMonadLog%" + <> "} %date% %cpu% | %memory% * %swap% | %wlxd03745e1e87bwi%" + <> "{ %kbd% %time%" + } + +myCommands :: [Runnable] +myCommands = + [ Run $ + Cpu + [ "--template", "Cpu: " + , "--suffix" , "True" + , "--Low" , "3" + , "--High" , "50" + , "--low" , colorGreen + , "--normal" , colorYellow + , "--high" , colorRed + ] + 10 + , Run $ Memory ["-t","Mem: %"] 10 + , Run $ Swap [] 10 + , Run $ Date "%a %d %b %Y" "date" (10 `seconds`) + , Run $ Date "%H:%M:%S" "time" (1 `seconds`) + , Run $ Kbd [("us(dvorak)", "us"), ("ru", "ru")] + , Run $ XMonadLog + , Run $ + Wireless + "wlxd03745e1e87b" + [ "--template", " " + , "--suffix" , "True" + , "--Low" , "40" + , "--High" , "70" + , "--low" , colorRed + , "--normal" , colorYellow + , "--high" , colorGreen + ] + (10 `seconds`) + ] + where + seconds, minutes :: Int -> Int + seconds = (* 10) + minutes = (60 *) . seconds + +------------------------------------------------------------------------------ + +colorBg, colorFg, colorRed, colorGreen, colorYellow, colorCyan :: String +colorBg = "#222222" +colorFg = "#cccccc" +colorRed = "#ff5555" +colorGreen = "#50fa7b" +colorYellow = "#f1fa8c" +colorCyan = "#8be9fd" + +cyan, green, yellow :: String -> String +cyan = xmobarColor colorCyan "" +green = xmobarColor colorGreen "" +yellow = xmobarColor colorYellow "" + +regularFont, boldFont :: Int -> String +regularFont size = "xft:Fira Code:size=" <> show size <> ":antialias=true" +boldFont size = "xft:Fira Code:bold:size=" <> show size <> ":antialias=true" + +------------------------------------------------------------------------------ +{- | Use xmobar escape codes to output a string with given foreground and +background colors. + +Source: https://hackage.haskell.org/package/xmonad-contrib-0.15/docs/src/XMonad.Hooks.DynamicLog.html#xmobarColor +-} +xmobarColor + :: String -- ^ foreground color: a color name, or #rrggbb format + -> String -- ^ background color + -> String -- ^ output string + -> String +xmobarColor fg bg = wrap open "" + where + open :: String = concat [" bg, ">"] + +-- | Wrap a string in delimiters, unless it is empty. +-- Source: https://hackage.haskell.org/package/xmonad-contrib-0.15/docs/src/XMonad.Hooks.DynamicLog.html#wrap +wrap + :: String -- ^ left delimiter + -> String -- ^ right delimiter + -> String -- ^ output string + -> String +wrap _ _ "" = "" +wrap l r m = l <> m <> r diff --git a/programs/xmonad/xmobar/stack.yaml b/programs/xmonad/xmobar/stack.yaml new file mode 100644 index 0000000..bf45b68 --- /dev/null +++ b/programs/xmonad/xmobar/stack.yaml @@ -0,0 +1,74 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/2.yaml + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# subdirs: +# - auto-update +# - wai +packages: +- . + +# Dependency packages to be pulled from upstream that are not in the resolver. +# These entries can reference officially published versions as well as +# forks / in-progress versions pinned to a git hash. For example: +# +# extra-deps: +# - acme-missiles-0.3 +# - git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# +extra-deps: +- xmobar-0.42 +- X11-xft-0.3.4 +- iwlib-0.1.0 + +# Override default flag values for local packages and extra-deps +flags: + xmobar: + with_xft: true + with_iwlib: true + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=2.7" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/programs/xmonad/xmobar/stack.yaml.lock b/programs/xmonad/xmobar/stack.yaml.lock new file mode 100644 index 0000000..02fcc33 --- /dev/null +++ b/programs/xmonad/xmobar/stack.yaml.lock @@ -0,0 +1,34 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: xmobar-0.42@sha256:a4583cea362e6e10a9633dc083987377a6016c1c0756802ef06dbb6c2ef77e30,14676 + pantry-tree: + size: 9019 + sha256: b35b11bd2c2656dc0f033c530a76a7803e48857859802551980fef35de112ba0 + original: + hackage: xmobar-0.42 +- completed: + hackage: X11-xft-0.3.4@sha256:e08bd69d24c40f1a33e6c87964f200656da77ad6a1fbdf6a4073dcb967e65599,1380 + pantry-tree: + size: 330 + sha256: 0dad74fea9135433d0f4ca7a65dba6c8ac99136bb6cacf901d2ddf795846d0f1 + original: + hackage: X11-xft-0.3.4 +- completed: + hackage: iwlib-0.1.0@sha256:226e4582d6878166a172ff98c868e25c4ed478ab28ab493498e464b1fe19d39a,921 + pantry-tree: + size: 259 + sha256: f867a93991b791adf4c65bb91f385effee7e18bd78d8e0a61fd03f42f6073705 + original: + hackage: iwlib-0.1.0 +snapshots: +- completed: + size: 617368 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/2.yaml + sha256: e7e57649a12f6178d1158e4b6f1f1885ed56d210ae6174385271cecc9b1ea974 + original: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/2.yaml diff --git a/programs/xmonad/xmobar/xmobarrc.cabal b/programs/xmonad/xmobar/xmobarrc.cabal new file mode 100644 index 0000000..3c2c529 --- /dev/null +++ b/programs/xmonad/xmobar/xmobarrc.cabal @@ -0,0 +1,26 @@ +cabal-version: 2.2 + +-- This file has been generated from package.yaml by hpack version 0.34.4. +-- +-- see: https://github.com/sol/hpack + +name: xmobarrc +version: 0.1.0 +synopsis: My xmobar configuration +homepage: https://github.com/pleshevskiy/myconfig +author: Pleshevskiy +maintainer: dmitriy@ideascup.me +license: Beerware +build-type: Simple + +executable xmobar + hs-source-dirs: + src + main-is: xmobar.hs + other-modules: + Paths_xmobarrc + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base + , xmobar + default-language: Haskell2010