Preface

Goal: Show A simple trick of Debugging Conky

Since we utilize a lot of Conky in Tiling WM Tutorial, we need to find a way to debug, just in case we encounter undesired result.

Have fun with this cheap trick.

Table of Content


1: Simple Conky

Suppose that you have an original code as below that need to be debugged.

Source:

conky.config = {
    out_to_x = false,
    out_to_console = true,
    short_units = true,
    update_interval = 1
}

conky.text = [[\
${time %a %b %d %H:%M:%S}\
]]

All you need to do is to inject tput cup 0 0 in the terminal to put terminal cursor in top left, for each time conky interval. The issue is how to transform this tput executable into conky text. All we need to do is to exec this tput in terminal environment.

We need to alter this code a bit.


2: Altered Conky

The debug code after injection of additional debugging utilities is as below

Source:

conky.config = {
    out_to_x = false,
    out_to_console = true,
    short_units = true,
    update_interval = 1
}

-- Lua Function Demo 
-- https://github.com/brndnmtthws/conky/issues/62

function exec(command)
    local file = assert(io.popen(command, 'r'))
    local s = file:read('*all')
    file:close()

    s = string.gsub(s, '^%s+', '') 
    s = string.gsub(s, '%s+$', '') 
    s = string.gsub(s, '[\n\r]+', ' ')

    return s
end


function gototopleft()
  return exec('tput cup 0 0') 
end

conky.text = gototopleft() .. [[\
${time %a %b %d %H:%M:%S}\
]]

Now you can run on terminal.

$ clear && conky -c ~/Documents/standalone/lang/assets/debug.lua

And get each conky result, always running from top left terminal.


3: Real Life Example

Since the code above just dump too simple date. We need to something more complex. Something error prone in need of debugging.

Here is another example of Conky as a feed to Dzen2 conky-example/conky.sh and conky-example/conky.lua.

Dzen2 Decorated Conky Dzen2 Example

Source:

#!/usr/bin/env bash

clear
conky -c ~/Documents/standalone/dzen2/debug/conky.lua

Now you can see the raw text before it become feed to dzen2.

Dzen2 Decorated Conky Dzen2 Example


Conclusion

Just another cheap tool to have fun with. That is all for now. Thank you for reading.