From 63303977071f34d8142709960e8dae97cea1951e Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 9 Aug 2022 23:48:44 +0100 Subject: examples -> etc --- doc/plugins.org | 8 +-- doc/quick-start.org | 9 ++- doc/using-haskell.org | 4 +- etc/build | 17 +++++ etc/padding-icon.sh | 56 +++++++++++++++ etc/status.sh | 56 +++++++++++++++ etc/xmobar.config | 39 +++++++++++ etc/xmobar.el | 164 ++++++++++++++++++++++++++++++++++++++++++++ etc/xmobar.hs | 77 +++++++++++++++++++++ etc/xmonadpropwrite.hs | 41 +++++++++++ examples/build | 17 ----- examples/cirrus.yml | 39 ----------- examples/gh-ci.yml | 77 --------------------- examples/padding-icon.sh | 56 --------------- examples/status.sh | 56 --------------- examples/xmobar.config | 39 ----------- examples/xmobar.el | 164 -------------------------------------------- examples/xmobar.hs | 77 --------------------- examples/xmonadpropwrite.hs | 41 ----------- readme.org | 2 +- xmobar.cabal | 13 ++-- 21 files changed, 469 insertions(+), 583 deletions(-) create mode 100644 etc/build create mode 100755 etc/padding-icon.sh create mode 100755 etc/status.sh create mode 100644 etc/xmobar.config create mode 100644 etc/xmobar.el create mode 100644 etc/xmobar.hs create mode 100644 etc/xmonadpropwrite.hs delete mode 100644 examples/build delete mode 100644 examples/cirrus.yml delete mode 100644 examples/gh-ci.yml delete mode 100755 examples/padding-icon.sh delete mode 100755 examples/status.sh delete mode 100644 examples/xmobar.config delete mode 100644 examples/xmobar.el delete mode 100644 examples/xmobar.hs delete mode 100644 examples/xmonadpropwrite.hs diff --git a/doc/plugins.org b/doc/plugins.org index 558bdef..ccf5780 100644 --- a/doc/plugins.org +++ b/doc/plugins.org @@ -1385,9 +1385,9 @@ - Aliases to =PropName= - Reads the X property named by =PropName= (a string) and displays its - value. The [[../examples/xmonadpropwrite.hs][examples/xmonadpropwrite.hs script]] in xmobar's distribution - can be used to set the given property from the output of any other - program or script. + value. The [[../etc/xmonadpropwrite.hs][etc/xmonadpropwrite.hs script]] in xmobar's distribution can be + used to set the given property from the output of any other program or + script. *** =UnsafeXPropertyLog PropName= @@ -1480,7 +1480,7 @@ =/tmp/xmobar_status= will reveal xmonad for 1.5 seconds and temporarily overwrite the window titles. - - Take a look at [[../examples/status.sh][examples/status.sh]] + - Take a look at [[../etc/status.sh][etc/status.sh]] - Expands environment variables for the pipe path diff --git a/doc/quick-start.org b/doc/quick-start.org index 4b060e2..a206a45 100644 --- a/doc/quick-start.org +++ b/doc/quick-start.org @@ -3,9 +3,8 @@ Xmobar can either be configured using the configuration language, or [[file:using-haskell.org][used as a Haskell library]] (similar to xmonad) and compiled with your specific configuration. For an example of a configuration file using the plain -configuration language, see [[../examples/xmobar.config][examples/xmobar.config]], and you can have a look at -[[../examples/xmobar.hs][examples/xmobar.hs]] for an example of how to write your own xmobar using -Haskell. +configuration language, see [[../etc/xmobar.config][etc/xmobar.config]], and you can have a look at +[[../etc/xmobar.hs][etc/xmobar.hs]] for an example of how to write your own xmobar using Haskell. * Command Line Options @@ -432,7 +431,7 @@ Haskell. Other options are ~Ansi~, ~Pango~, and ~Swaybar~. ** Showing xmobar output in Emacs tab or mode line Using xmobar's ANSI color text ouput, one can plug it inside Emacs, and - display your monitors in the mode line or the tab bar. The [[../examples/xmobar.el][xmobar.el + display your monitors in the mode line or the tab bar. The [[../etc/xmobar.el][xmobar.el package]] provides a simple way of doing it. ** Using xmobar in wayland with swaybar or waybar :PROPERTIES: @@ -476,7 +475,7 @@ Haskell. dynamically xmobar's size and run it alongside a system tray widget such as trayer or stalonetray (although the idea is not limited to trays, really). For your convenience, there is a version of Jonas' script in - [[../examples/padding-icon.sh][examples/padding-icon.sh]]. + [[../etc/padding-icon.sh][etc/padding-icon.sh]]. ** Signal handling diff --git a/doc/using-haskell.org b/doc/using-haskell.org index 667ab4d..4020557 100644 --- a/doc/using-haskell.org +++ b/doc/using-haskell.org @@ -75,7 +75,7 @@ =run= can be used for simpler plugins. If you define only =run= the plugin will be run every second. To overwrite this default you just need to implement =rate=, which must return the number of tenth of seconds between - every successive runs. See [[../examples/xmobar.hs][examples/xmobar.hs]] for an example of a plugin + every successive runs. See [[../etc/xmobar.hs][etc/xmobar.hs]] for an example of a plugin that runs just once, and [[../src/Xmobar/Plugins/Date.hs][src/Xmobar/Plugins/Date.hs]] for one that implements =rate=. @@ -114,7 +114,7 @@ To use your new plugin, you just need to use a pure Haskell configuration for xmobar (as explained [[#xmobar-in-haskell][above]]) and load your definitions in your =xmobar.hs= - file. You can see an example in [[../examples/xmobar.hs][examples/xmobar.hs]] showing you how to write + file. You can see an example in [[../etc/xmobar.hs][etc/xmobar.hs]] showing you how to write a Haskell configuration that uses a new plugin, all in one file. When xmobar runs with the full path to that Haskell file as its argument diff --git a/etc/build b/etc/build new file mode 100644 index 0000000..9e9eb72 --- /dev/null +++ b/etc/build @@ -0,0 +1,17 @@ +#!/usr/bin/bash + +# An example build script that directs ghc to use a temporary directory for its +# intermediate files instead of writing them into XMOBAR_CONFIG_DIR. This +# allows using a read-only XMOBAR_CONFIG_DIR. To use this script, place it in +# XMOBAR_CONFIG_DIR and call it "build". + +bin=$1 +object_dir=$(mktemp -d) + +default_build_args=(--make xmobar.hs -i -ilib -fforce-recomp -main-is main -v0 -o "$bin" -threaded -rtsopts -with-rtsopts -V0) # From src/Xmobar/App/Compile.hs +extra_build_args=(-odir "$object_dir" -hidir "$object_dir") + +ghc "${default_build_args[@]}" "${extra_build_args[@]}" +status=$? +rm -r "$object_dir" +exit $status diff --git a/etc/padding-icon.sh b/etc/padding-icon.sh new file mode 100755 index 0000000..ec3ada2 --- /dev/null +++ b/etc/padding-icon.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Detects the width of running window with name given as first +# argument (xprop name '$1') and creates an XPM icon of that width, +# 1px height, and transparent. Outputs an -tag for use in +# xmobar to display the generated XPM icon. +# +# Run script from xmobar and trayer: +# `Run Com "/where/ever/padding-icon.sh" ["panel"] "trayerpad" 10` +# and use `%trayerpad%` in your template. +# or, if you're using for instance stalonetray: +# `Run Com "/where/ever/padding-icon.sh" ["stalonetray"] "tray" 10` + +# Very heavily based on Jonas Camillus Jeppensen code +# https://codeberg.org/xmobar/xmobar/issues/239#issuecomment-233206552 + +# Function to create a transparent Wx1 px XPM icon +create_xpm_icon () { +timestamp=$(date) +pixels=$(for i in `seq $1`; do echo -n "."; done) + +cat << EOF > "$2" +/* XPM * +static char * trayer_pad_xpm[] = { +/* This XPM icon is used for padding in xmobar to */ +/* leave room for trayer-srg. It is dynamically */ +/* updated by by trayer-pad-icon.sh which is run */ +/* by xmobar. */ +/* Created: ${timestamp} */ +/* */ +"$1 1 1 1", +/* Colors (none: transparent) */ +". c none", +/* Pixels */ +"$pixels" +}; +EOF +} + +# panel window name +pname=${1:-panel} + +# Width of the trayer window +width=$(xprop -name $pname | grep 'program specified minimum size' | cut -d ' ' -f 5) + +# Icon file name +iconfile="/tmp/$pname-padding-${width:-0}px.xpm" + +# If the desired icon does not exist create it +if [ ! -f $iconfile ] +then + create_xpm_icon $width $iconfile +fi + +# Output the icon tag for xmobar +echo "" diff --git a/etc/status.sh b/etc/status.sh new file mode 100755 index 0000000..151728b --- /dev/null +++ b/etc/status.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +STATUSPIPE="/tmp/xmobar_status_jrk" + +function isMuted () { + # retrieve mute status + # return an arbitrary string for true or nothing at all + echo +} + +function getPercent () { + # somehow retrieve the percent value as plain int (e.g. "66") + echo "66" +} + +function percentBar () { + local i=1 res= + normal=47 high=80 + fgColor='#657b83' mutedColor='#cb4b16' + lowColor='#859900' midColor='#b58900' + highColor='#cb4b16' + + bar="$(echo -ne "\u2588")" + percent="$( getPercent )" + muted="$( isMuted )" + + if [ -n "$muted" ]; then + res="" + else + res="" + fi + + while [ $i -lt $percent ]; do + if [ $i -eq $normal -a -z "$muted" ]; then + res+="" + elif [ $i -eq $high -a -z "$muted" ]; then + res+="" + fi + + res+=$bar + i=$((i+1)) + done + + res+="" + + while [ $i -lt 100 ]; do + res+='-' + i=$((i+1)) + done + + echo "$res" +} + +[[ -p $STATUSPIPE ]] || mkfifo $STATUSPIPE + +echo "$( percentBar )" > "$STATUSPIPE" diff --git a/etc/xmobar.config b/etc/xmobar.config new file mode 100644 index 0000000..e951b67 --- /dev/null +++ b/etc/xmobar.config @@ -0,0 +1,39 @@ +Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*" + , additionalFonts = [] + , borderColor = "black" + , border = TopB + , bgColor = "black" + , fgColor = "grey" + , alpha = 255 + , position = Top + , textOffset = -1 + , iconOffset = -1 + , lowerOnStart = True + , pickBroadest = False + , persistent = False + , hideOnStart = False + , iconRoot = "." + , allDesktops = True + , overrideRedirect = True + , textOutputFormat = Ansi + , commands = [ Run Weather "EGPF" ["-t",": C", + "-L","18","-H","25", + "--normal","green", + "--high","red", + "--low","lightblue"] 36000 + , Run Network "eth0" ["-L","0","-H","32", + "--normal","green","--high","red"] 10 + , Run Network "eth1" ["-L","0","-H","32", + "--normal","green","--high","red"] 10 + , Run Cpu ["-L","3","-H","50", + "--normal","green","--high","red"] 10 + , Run Memory ["-t","Mem: %"] 10 + , Run Swap [] 10 + , Run Com "uname" ["-s","-r"] "" 36000 + , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 + ] + , sepChar = "%" + , alignSep = "}{" + , template = "%cpu% | %memory% * %swap% | %eth0% - %eth1% }\ + \{ %date%| %EGPF% | %uname%" + } diff --git a/etc/xmobar.el b/etc/xmobar.el new file mode 100644 index 0000000..905af3d --- /dev/null +++ b/etc/xmobar.el @@ -0,0 +1,164 @@ +;; xmobar.el --- Display xmobar text output -*- lexical-binding: t -*- + +;; Copyright 2022 jao +;; Version: 0.0.1 +;; Package-Requires: ((emacs "28.1")) +;; Keywords: unix + +;; Heavily inspired by Steven Allen's https://github.com/Stebalien/i3bar.el + +;; This file is not part of GNU Emacs. + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; Displays the output of an xmobar command in the Emacs mode-line (or tab-line). + +;;; Code: + +(eval-when-compile (require 'cl-lib)) + +(require 'tab-bar) +(require 'xterm-color nil t) + +(defgroup xmobar nil + "xmobar status display for Emacs." + :version "0.0.1" + :group 'mode-line) + +(defcustom xmobar-command '("xmobar" "-TAnsi") + "The xmobar command and flags." + :type '(choice (string :tag "Shell Command") + (repeat (string)))) + +(defcustom xmobar-tab-bar t + "Whether to dispaly xmobar output in the tab bar." + :type 'boolean) + +(defcustom xmobar-tab-split nil + "Split on this string for `xmobar-left-string' and `xmobar-right-string'." + :type 'string) + +(defcustom xmobar-tab-bar-format + '(xmobar-left-string tab-bar-format-align-right xmobar-right-string) + "Format for the tab bar when `xmobar-tab-bar' is t." + :type 'list) + +(defvar xmobar--process nil + "The running xmobar process, if any.") + +(defvar xmobar--left-string "") + +(defvar xmobar-string "" + "The xmobar string to be displayed in the mode-line or tab-bar.") + +(put 'xmobar-string 'risky-local-variable t) + +(defvar xmobar--colorize-fn + (if (featurep 'xterm-color) #'xterm-color-filter #'ansi-color-apply)) + +(defvar xmobar--old-tab-format tab-bar-format) + +(defun xmobar-string () xmobar-string) +(defun xmobar-right-string () xmobar-string) +(defun xmobar-left-string () xmobar--left-string) + +;;;###autoload +(define-minor-mode xmobar-mode + "Display an xmobar in the mode-line." + :global t :group 'xmobar + (xmobar--stop) + (if xmobar-mode + (progn (if xmobar-tab-bar + (progn + (setq xmobar--old-tab-format tab-bar-format) + (setq tab-bar-format xmobar-tab-bar-format) + (tab-bar-mode 1)) + (or global-mode-string (setq global-mode-string '(""))) + (unless (memq 'xmobar-string global-mode-string) + (setq global-mode-string + (append global-mode-string '(xmobar-string))))) + (xmobar--start)) + (when xmobar-tab-bar (setq tab-bar-format xmobar--old-tab-format)))) + +(defun xmobar--update (update) + "Apply an UPDATE to the xmobar bar." + (when xmobar-mode + (let* ((str (funcall xmobar--colorize-fn update)) + (strs (and xmobar-tab-split (split-string str xmobar-tab-split)))) + (setq xmobar-string (if strs (cadr strs) str) + xmobar--left-string (or (car strs) ""))) + (force-mode-line-update t))) + +(defun xmobar--process-filter (proc string) + "Process output from the xmobar process." + (let ((buf (process-buffer proc))) + (when (buffer-live-p buf) + (with-current-buffer buf + ;; Write the input to the buffer (might be partial). + (save-excursion + (goto-char (process-mark proc)) + (insert string) + (set-marker (process-mark proc) (point))) + (when (string-match-p "\n$" string) + (xmobar--update (buffer-string)) + (delete-region (point-min) (point-max))))))) + +(defun xmobar--process-sentinel (proc status) + "Handle events from the xmobar process (PROC). +If the process has exited, this function stores the exit STATUS in +`xmobar-string'." + (unless (process-live-p proc) + (setq xmobar--process nil) + (let ((buf (process-buffer proc))) + (when (and buf (buffer-live-p buf)) (kill-buffer buf))) + (setq xmobar-string (format "xmobar: %s" status) xmobar--left-string ""))) + +(defun xmobar--start () + "Start xmobar." + (xmobar--stop) + (condition-case err + (setq xmobar--process + (make-process + :name "xmobar" + :buffer " *xmobar process*" + :stderr " *xmobar stderr*" + :command (ensure-list xmobar-command) + :connection-type 'pipe + :noquery t + :sentinel #'xmobar--process-sentinel + :filter #'xmobar--process-filter)) + (error + (setq xmobar-string + (format "starting xmobar: %s" (error-message-string err)) + xmobar--left-string "")))) + +(defun xmobar--stop () + "Stop xmobar." + (when (and xmobar--process (process-live-p xmobar--process)) + (delete-process xmobar--process)) + (setq xmobar-string "" xmobar--left-string "")) + +;;;###autoload +(defun xmobar-restart () + "Restart the xmobar program." + (interactive) + (unless xmobar-mode (user-error "The xmobar-mode is not enabled")) + (xmobar--start)) + +(provide 'xmobar) +;;; xmobar.el ends here diff --git a/etc/xmobar.hs b/etc/xmobar.hs new file mode 100644 index 0000000..f8434fe --- /dev/null +++ b/etc/xmobar.hs @@ -0,0 +1,77 @@ +------------------------------------------------------------------------------ +-- | +-- 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 + +-- Example user-defined plugin + +data HelloWorld = HelloWorld + deriving (Read, Show) + +instance Exec HelloWorld where + alias HelloWorld = "hw" + run HelloWorld = return "Hello World!!" + +-- Configuration, using predefined monitors as well as our HelloWorld +-- plugin: + +config :: Config +config = defaultConfig { + font = "xft:Sans Mono-9" + , additionalFonts = [] + , borderColor = "black" + , border = TopB + , bgColor = "black" + , fgColor = "grey" + , alpha = 255 + , position = Top + , textOffset = -1 + , iconOffset = -1 + , lowerOnStart = True + , pickBroadest = False + , persistent = False + , hideOnStart = False + , iconRoot = "." + , allDesktops = True + , overrideRedirect = True + , textOutputFormat = Ansi + , commands = [ Run $ Weather "EGPH" ["-t",": C", + "-L","18","-H","25", + "--normal","green", + "--high","red", + "--low","lightblue"] 36000 + , Run $ Network "eth0" ["-L","0","-H","32", + "--normal","green","--high","red"] 10 + , Run $ Network "eth1" ["-L","0","-H","32", + "--normal","green","--high","red"] 10 + , Run $ Cpu ["-L","3","-H","50", + "--normal","green","--high","red"] 10 + , Run $ Memory ["-t","Mem: %"] 10 + , Run $ Swap [] 10 + , Run $ Com "uname" ["-s","-r"] "" 36000 + , Run $ Date "%a %b %_d %Y %H:%M:%S" "date" 10 + , Run HelloWorld + ] + , sepChar = "%" + , alignSep = "}{" + , template = "%cpu% | %memory% * %swap% | %eth0% - %eth1% }\ + \ %hw% { %date%| %EGPH% | %uname%" +} + +main :: IO () +main = configFromArgs config >>= xmobar diff --git a/etc/xmonadpropwrite.hs b/etc/xmonadpropwrite.hs new file mode 100644 index 0000000..f3f4a5d --- /dev/null +++ b/etc/xmonadpropwrite.hs @@ -0,0 +1,41 @@ +-- Copyright Spencer Janssen +-- Tomas Janousek +-- BSD3 (see LICENSE) +-- +-- Reads from standard input and writes to an X propery on root window. +-- To be used with XPropertyLog: +-- Add it to commands: +-- Run XPropertyLog "_XMONAD_LOG_CUSTOM" +-- Add it to the template: +-- template = "... %_XMONAD_LOG_CUSTOM% ..." +-- Run: +-- $ blah blah | xmonadpropwrite _XMONAD_LOG_CUSTOM + +import Control.Monad +import Graphics.X11 +import Graphics.X11.Xlib.Extras +import qualified Data.ByteString as B +import Foreign.C (CChar) +import System.IO +import System.Environment + +main = do + atom <- flip fmap getArgs $ \args -> case args of + [a] -> a + _ -> "_XMONAD_LOG" + + d <- openDisplay "" + xlog <- internAtom d atom False + ustring <- internAtom d "UTF8_STRING" False + + root <- rootWindow d (defaultScreen d) + + forever $ do + msg <- B.getLine + changeProperty8 d root xlog ustring propModeReplace (encodeCChar msg) + sync d True + + return () + +encodeCChar :: B.ByteString -> [CChar] +encodeCChar = map fromIntegral . B.unpack diff --git a/examples/build b/examples/build deleted file mode 100644 index 9e9eb72..0000000 --- a/examples/build +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/bash - -# An example build script that directs ghc to use a temporary directory for its -# intermediate files instead of writing them into XMOBAR_CONFIG_DIR. This -# allows using a read-only XMOBAR_CONFIG_DIR. To use this script, place it in -# XMOBAR_CONFIG_DIR and call it "build". - -bin=$1 -object_dir=$(mktemp -d) - -default_build_args=(--make xmobar.hs -i -ilib -fforce-recomp -main-is main -v0 -o "$bin" -threaded -rtsopts -with-rtsopts -V0) # From src/Xmobar/App/Compile.hs -extra_build_args=(-odir "$object_dir" -hidir "$object_dir") - -ghc "${default_build_args[@]}" "${extra_build_args[@]}" -status=$? -rm -r "$object_dir" -exit $status diff --git a/examples/cirrus.yml b/examples/cirrus.yml deleted file mode 100644 index 6105386..0000000 --- a/examples/cirrus.yml +++ /dev/null @@ -1,39 +0,0 @@ -freebsd_instance: - image_family: freebsd-13-0 - -build_task: - env: - CONFIG: "--enable-tests --enable-benchmarks -fwith_mpd -fwith_xft" - - # caches the freebsd package downloads - # saves probably just a couple of seconds, but hey... - pkg_cache: - folder: /var/cache/pkg - - install_script: - - pkg install -y ghc hs-hlint xorg-libraries hs-cabal-install git autoconf libmpdclient pkgconf libXft hs-hspec-discover - - # cache the hackage index file and downloads which are - # cabal v2-update downloads an incremental update, so we don't need to keep this up2date - packages_cache: - # warning: don't use ~/.cabal here, this will break the cache - folder: /.cabal/packages - reupload_on_changes: false - - # cache the dependencies built by cabal - # they have to be uploaded on every change to make the next build fast - store_cache: - # warning: don't use ~/.cabal here, this will break the cache - folder: /.cabal/store - fingerprint_script: cat xmobar.cabal - reupload_on_changes: true - - build_script: - - cabal v2-update - - timeout 1800 cabal v2-build -j4 $CONFIG || (($?==124)) - - lint_script: - - hlint src - - test_script: - - cabal v2-test -j4 $CONFIG diff --git a/examples/gh-ci.yml b/examples/gh-ci.yml deleted file mode 100644 index e720e9e..0000000 --- a/examples/gh-ci.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Haskell CI (PRs) - -on: - pull_request: - branches: [ master ] - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - cabal: ["3.2"] - ghc: ["8.4", "8.6", "8.8.3", "8.10"] - env: - CONFIG: "--enable-tests --enable-benchmarks -fall_extensions" - - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-haskell@v1 - with: - ghc-version: ${{ matrix.ghc }} - cabal-version: ${{ matrix.cabal }} - - - name: Cache - uses: actions/cache@v1 - env: - cache-name: cache-cabal - with: - path: ~/.cabal - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Install packages - run: | - sudo apt-get update - sudo apt-get install -y xorg-dev - sudo apt-get install -y libasound2-dev libxpm-dev libmpd-dev libxrandr-dev - sudo apt-get install -y happy c2hs hspec-discover - - - name: Install dependencies - run: | - cabal update - cabal build --dependencies-only $CONFIG - - - name: Build - run: cabal build $CONFIG - - - name: Run hlint - run: | - wget https://raw.github.com/ndmitchell/hlint/master/misc/travis.sh - sh ./travis.sh src - - name: Run tests - run: cabal test - - # build-freebsd: - # runs-on: macos-latest - # env: - # CONFIG: "--enable-tests --enable-benchmarks -fwith_xft -fwith_mpd" - - # steps: - # - uses: actions/checkout@v2 - - # - name: Install dependencies - # uses: vmactions/freebsd-vm@v0.1.5 - # with: - # usesh: true - # prepare: pkg install -y ghc hs-hlint xorg-libraries hs-cabal-install git autoconf - # run: | - # cabal update - # cabal build --dependencies-only $CONFIG - # cabal build $CONFIG - # hlint - # cabal test diff --git a/examples/padding-icon.sh b/examples/padding-icon.sh deleted file mode 100755 index ec3ada2..0000000 --- a/examples/padding-icon.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -# Detects the width of running window with name given as first -# argument (xprop name '$1') and creates an XPM icon of that width, -# 1px height, and transparent. Outputs an -tag for use in -# xmobar to display the generated XPM icon. -# -# Run script from xmobar and trayer: -# `Run Com "/where/ever/padding-icon.sh" ["panel"] "trayerpad" 10` -# and use `%trayerpad%` in your template. -# or, if you're using for instance stalonetray: -# `Run Com "/where/ever/padding-icon.sh" ["stalonetray"] "tray" 10` - -# Very heavily based on Jonas Camillus Jeppensen code -# https://codeberg.org/xmobar/xmobar/issues/239#issuecomment-233206552 - -# Function to create a transparent Wx1 px XPM icon -create_xpm_icon () { -timestamp=$(date) -pixels=$(for i in `seq $1`; do echo -n "."; done) - -cat << EOF > "$2" -/* XPM * -static char * trayer_pad_xpm[] = { -/* This XPM icon is used for padding in xmobar to */ -/* leave room for trayer-srg. It is dynamically */ -/* updated by by trayer-pad-icon.sh which is run */ -/* by xmobar. */ -/* Created: ${timestamp} */ -/* */ -"$1 1 1 1", -/* Colors (none: transparent) */ -". c none", -/* Pixels */ -"$pixels" -}; -EOF -} - -# panel window name -pname=${1:-panel} - -# Width of the trayer window -width=$(xprop -name $pname | grep 'program specified minimum size' | cut -d ' ' -f 5) - -# Icon file name -iconfile="/tmp/$pname-padding-${width:-0}px.xpm" - -# If the desired icon does not exist create it -if [ ! -f $iconfile ] -then - create_xpm_icon $width $iconfile -fi - -# Output the icon tag for xmobar -echo "" diff --git a/examples/status.sh b/examples/status.sh deleted file mode 100755 index 151728b..0000000 --- a/examples/status.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -STATUSPIPE="/tmp/xmobar_status_jrk" - -function isMuted () { - # retrieve mute status - # return an arbitrary string for true or nothing at all - echo -} - -function getPercent () { - # somehow retrieve the percent value as plain int (e.g. "66") - echo "66" -} - -function percentBar () { - local i=1 res= - normal=47 high=80 - fgColor='#657b83' mutedColor='#cb4b16' - lowColor='#859900' midColor='#b58900' - highColor='#cb4b16' - - bar="$(echo -ne "\u2588")" - percent="$( getPercent )" - muted="$( isMuted )" - - if [ -n "$muted" ]; then - res="" - else - res="" - fi - - while [ $i -lt $percent ]; do - if [ $i -eq $normal -a -z "$muted" ]; then - res+="" - elif [ $i -eq $high -a -z "$muted" ]; then - res+="" - fi - - res+=$bar - i=$((i+1)) - done - - res+="" - - while [ $i -lt 100 ]; do - res+='-' - i=$((i+1)) - done - - echo "$res" -} - -[[ -p $STATUSPIPE ]] || mkfifo $STATUSPIPE - -echo "$( percentBar )" > "$STATUSPIPE" diff --git a/examples/xmobar.config b/examples/xmobar.config deleted file mode 100644 index e951b67..0000000 --- a/examples/xmobar.config +++ /dev/null @@ -1,39 +0,0 @@ -Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*" - , additionalFonts = [] - , borderColor = "black" - , border = TopB - , bgColor = "black" - , fgColor = "grey" - , alpha = 255 - , position = Top - , textOffset = -1 - , iconOffset = -1 - , lowerOnStart = True - , pickBroadest = False - , persistent = False - , hideOnStart = False - , iconRoot = "." - , allDesktops = True - , overrideRedirect = True - , textOutputFormat = Ansi - , commands = [ Run Weather "EGPF" ["-t",": C", - "-L","18","-H","25", - "--normal","green", - "--high","red", - "--low","lightblue"] 36000 - , Run Network "eth0" ["-L","0","-H","32", - "--normal","green","--high","red"] 10 - , Run Network "eth1" ["-L","0","-H","32", - "--normal","green","--high","red"] 10 - , Run Cpu ["-L","3","-H","50", - "--normal","green","--high","red"] 10 - , Run Memory ["-t","Mem: %"] 10 - , Run Swap [] 10 - , Run Com "uname" ["-s","-r"] "" 36000 - , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 - ] - , sepChar = "%" - , alignSep = "}{" - , template = "%cpu% | %memory% * %swap% | %eth0% - %eth1% }\ - \{ %date%| %EGPF% | %uname%" - } diff --git a/examples/xmobar.el b/examples/xmobar.el deleted file mode 100644 index 905af3d..0000000 --- a/examples/xmobar.el +++ /dev/null @@ -1,164 +0,0 @@ -;; xmobar.el --- Display xmobar text output -*- lexical-binding: t -*- - -;; Copyright 2022 jao -;; Version: 0.0.1 -;; Package-Requires: ((emacs "28.1")) -;; Keywords: unix - -;; Heavily inspired by Steven Allen's https://github.com/Stebalien/i3bar.el - -;; This file is not part of GNU Emacs. - -;; This file is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. - -;; This file is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to -;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. - -;;; Commentary: - -;; Displays the output of an xmobar command in the Emacs mode-line (or tab-line). - -;;; Code: - -(eval-when-compile (require 'cl-lib)) - -(require 'tab-bar) -(require 'xterm-color nil t) - -(defgroup xmobar nil - "xmobar status display for Emacs." - :version "0.0.1" - :group 'mode-line) - -(defcustom xmobar-command '("xmobar" "-TAnsi") - "The xmobar command and flags." - :type '(choice (string :tag "Shell Command") - (repeat (string)))) - -(defcustom xmobar-tab-bar t - "Whether to dispaly xmobar output in the tab bar." - :type 'boolean) - -(defcustom xmobar-tab-split nil - "Split on this string for `xmobar-left-string' and `xmobar-right-string'." - :type 'string) - -(defcustom xmobar-tab-bar-format - '(xmobar-left-string tab-bar-format-align-right xmobar-right-string) - "Format for the tab bar when `xmobar-tab-bar' is t." - :type 'list) - -(defvar xmobar--process nil - "The running xmobar process, if any.") - -(defvar xmobar--left-string "") - -(defvar xmobar-string "" - "The xmobar string to be displayed in the mode-line or tab-bar.") - -(put 'xmobar-string 'risky-local-variable t) - -(defvar xmobar--colorize-fn - (if (featurep 'xterm-color) #'xterm-color-filter #'ansi-color-apply)) - -(defvar xmobar--old-tab-format tab-bar-format) - -(defun xmobar-string () xmobar-string) -(defun xmobar-right-string () xmobar-string) -(defun xmobar-left-string () xmobar--left-string) - -;;;###autoload -(define-minor-mode xmobar-mode - "Display an xmobar in the mode-line." - :global t :group 'xmobar - (xmobar--stop) - (if xmobar-mode - (progn (if xmobar-tab-bar - (progn - (setq xmobar--old-tab-format tab-bar-format) - (setq tab-bar-format xmobar-tab-bar-format) - (tab-bar-mode 1)) - (or global-mode-string (setq global-mode-string '(""))) - (unless (memq 'xmobar-string global-mode-string) - (setq global-mode-string - (append global-mode-string '(xmobar-string))))) - (xmobar--start)) - (when xmobar-tab-bar (setq tab-bar-format xmobar--old-tab-format)))) - -(defun xmobar--update (update) - "Apply an UPDATE to the xmobar bar." - (when xmobar-mode - (let* ((str (funcall xmobar--colorize-fn update)) - (strs (and xmobar-tab-split (split-string str xmobar-tab-split)))) - (setq xmobar-string (if strs (cadr strs) str) - xmobar--left-string (or (car strs) ""))) - (force-mode-line-update t))) - -(defun xmobar--process-filter (proc string) - "Process output from the xmobar process." - (let ((buf (process-buffer proc))) - (when (buffer-live-p buf) - (with-current-buffer buf - ;; Write the input to the buffer (might be partial). - (save-excursion - (goto-char (process-mark proc)) - (insert string) - (set-marker (process-mark proc) (point))) - (when (string-match-p "\n$" string) - (xmobar--update (buffer-string)) - (delete-region (point-min) (point-max))))))) - -(defun xmobar--process-sentinel (proc status) - "Handle events from the xmobar process (PROC). -If the process has exited, this function stores the exit STATUS in -`xmobar-string'." - (unless (process-live-p proc) - (setq xmobar--process nil) - (let ((buf (process-buffer proc))) - (when (and buf (buffer-live-p buf)) (kill-buffer buf))) - (setq xmobar-string (format "xmobar: %s" status) xmobar--left-string ""))) - -(defun xmobar--start () - "Start xmobar." - (xmobar--stop) - (condition-case err - (setq xmobar--process - (make-process - :name "xmobar" - :buffer " *xmobar process*" - :stderr " *xmobar stderr*" - :command (ensure-list xmobar-command) - :connection-type 'pipe - :noquery t - :sentinel #'xmobar--process-sentinel - :filter #'xmobar--process-filter)) - (error - (setq xmobar-string - (format "starting xmobar: %s" (error-message-string err)) - xmobar--left-string "")))) - -(defun xmobar--stop () - "Stop xmobar." - (when (and xmobar--process (process-live-p xmobar--process)) - (delete-process xmobar--process)) - (setq xmobar-string "" xmobar--left-string "")) - -;;;###autoload -(defun xmobar-restart () - "Restart the xmobar program." - (interactive) - (unless xmobar-mode (user-error "The xmobar-mode is not enabled")) - (xmobar--start)) - -(provide 'xmobar) -;;; xmobar.el ends here diff --git a/examples/xmobar.hs b/examples/xmobar.hs deleted file mode 100644 index f8434fe..0000000 --- a/examples/xmobar.hs +++ /dev/null @@ -1,77 +0,0 @@ ------------------------------------------------------------------------------- --- | --- 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 - --- Example user-defined plugin - -data HelloWorld = HelloWorld - deriving (Read, Show) - -instance Exec HelloWorld where - alias HelloWorld = "hw" - run HelloWorld = return "Hello World!!" - --- Configuration, using predefined monitors as well as our HelloWorld --- plugin: - -config :: Config -config = defaultConfig { - font = "xft:Sans Mono-9" - , additionalFonts = [] - , borderColor = "black" - , border = TopB - , bgColor = "black" - , fgColor = "grey" - , alpha = 255 - , position = Top - , textOffset = -1 - , iconOffset = -1 - , lowerOnStart = True - , pickBroadest = False - , persistent = False - , hideOnStart = False - , iconRoot = "." - , allDesktops = True - , overrideRedirect = True - , textOutputFormat = Ansi - , commands = [ Run $ Weather "EGPH" ["-t",": C", - "-L","18","-H","25", - "--normal","green", - "--high","red", - "--low","lightblue"] 36000 - , Run $ Network "eth0" ["-L","0","-H","32", - "--normal","green","--high","red"] 10 - , Run $ Network "eth1" ["-L","0","-H","32", - "--normal","green","--high","red"] 10 - , Run $ Cpu ["-L","3","-H","50", - "--normal","green","--high","red"] 10 - , Run $ Memory ["-t","Mem: %"] 10 - , Run $ Swap [] 10 - , Run $ Com "uname" ["-s","-r"] "" 36000 - , Run $ Date "%a %b %_d %Y %H:%M:%S" "date" 10 - , Run HelloWorld - ] - , sepChar = "%" - , alignSep = "}{" - , template = "%cpu% | %memory% * %swap% | %eth0% - %eth1% }\ - \ %hw% { %date%| %EGPH% | %uname%" -} - -main :: IO () -main = configFromArgs config >>= xmobar diff --git a/examples/xmonadpropwrite.hs b/examples/xmonadpropwrite.hs deleted file mode 100644 index f3f4a5d..0000000 --- a/examples/xmonadpropwrite.hs +++ /dev/null @@ -1,41 +0,0 @@ --- Copyright Spencer Janssen --- Tomas Janousek --- BSD3 (see LICENSE) --- --- Reads from standard input and writes to an X propery on root window. --- To be used with XPropertyLog: --- Add it to commands: --- Run XPropertyLog "_XMONAD_LOG_CUSTOM" --- Add it to the template: --- template = "... %_XMONAD_LOG_CUSTOM% ..." --- Run: --- $ blah blah | xmonadpropwrite _XMONAD_LOG_CUSTOM - -import Control.Monad -import Graphics.X11 -import Graphics.X11.Xlib.Extras -import qualified Data.ByteString as B -import Foreign.C (CChar) -import System.IO -import System.Environment - -main = do - atom <- flip fmap getArgs $ \args -> case args of - [a] -> a - _ -> "_XMONAD_LOG" - - d <- openDisplay "" - xlog <- internAtom d atom False - ustring <- internAtom d "UTF8_STRING" False - - root <- rootWindow d (defaultScreen d) - - forever $ do - msg <- B.getLine - changeProperty8 d root xlog ustring propModeReplace (encodeCChar msg) - sync d True - - return () - -encodeCChar :: B.ByteString -> [CChar] -encodeCChar = map fromIntegral . B.unpack diff --git a/readme.org b/readme.org index 0a8c2d6..ee93fdc 100644 --- a/readme.org +++ b/readme.org @@ -127,7 +127,7 @@ channel, ~#xmobar~, at [[ircs://irc.libera.chat][Libera]]. inside a terminal o console, or its output piped to other applications, and there is no need for an X11 display. See [[./doc/quick-start.org#text-mode][Running xmobar in text mode]] for details. Using this mode, you could [[file:doc/quick-start.org#wayland][pipe xmobar's output to, say, swaybar]], - and use it in wayland, or, with the [[./examples/xmobar.el][xmobar.el]] package, show it in Emacs's + and use it in wayland, or, with the [[./etc/xmobar.el][xmobar.el]] package, show it in Emacs's tab bar. * Configuration and further documentation diff --git a/xmobar.cabal b/xmobar.cabal index 3098ec5..95c7a6f 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -17,11 +17,14 @@ cabal-version: >= 1.10 build-type: Simple extra-source-files: readme.org, changelog.md, - doc/quick-start.org, doc/plugins.org - examples/padding-icon.sh, - examples/xmobar.config, - examples/xmobar.hs, - examples/xmonadpropwrite.hs + doc/quick-start.org, + doc/plugins.org, + doc/compiling.org, + doc/using-haskell.org, + etc/padding-icon.sh, + etc/xmobar.config, + etc/xmobar.hs, + etc/xmonadpropwrite.hs source-repository head type: git -- cgit v1.2.3