From ee008b6e5478eba7714846b49fc2141b770bdd6b Mon Sep 17 00:00:00 2001 From: streetturtle Date: Mon, 9 Nov 2020 10:07:14 -0500 Subject: [PATCH] [github-contribution] add themes --- github-contributions-widget/README.md | 37 +++++++++++--- .../github-contributions-widget.lua | 44 +++++++++-------- .../screenshots/Thomashighbaugh.png | Bin 0 -> 384 bytes .../screenshots/classic.png | Bin 0 -> 494 bytes .../screenshots/dracula.png | Bin 0 -> 497 bytes .../screenshots/leftpad.png | Bin 0 -> 409 bytes .../screenshots/pink.png | Bin 0 -> 409 bytes .../{ => screenshots}/screenshot.jpg | Bin .../{ => screenshots}/screenshot1.jpg | Bin .../{ => screenshots}/screenshot2.jpg | Bin .../screenshots/standard.png | Bin 0 -> 408 bytes .../screenshots/teal.png | Bin 0 -> 409 bytes github-contributions-widget/themes.lua | 46 ++++++++++++++++++ 13 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 github-contributions-widget/screenshots/Thomashighbaugh.png create mode 100644 github-contributions-widget/screenshots/classic.png create mode 100644 github-contributions-widget/screenshots/dracula.png create mode 100644 github-contributions-widget/screenshots/leftpad.png create mode 100644 github-contributions-widget/screenshots/pink.png rename github-contributions-widget/{ => screenshots}/screenshot.jpg (100%) rename github-contributions-widget/{ => screenshots}/screenshot1.jpg (100%) rename github-contributions-widget/{ => screenshots}/screenshot2.jpg (100%) create mode 100644 github-contributions-widget/screenshots/standard.png create mode 100644 github-contributions-widget/screenshots/teal.png create mode 100644 github-contributions-widget/themes.lua diff --git a/github-contributions-widget/README.md b/github-contributions-widget/README.md index b7f6b93..7d02008 100644 --- a/github-contributions-widget/README.md +++ b/github-contributions-widget/README.md @@ -1,8 +1,12 @@ # Github Contributions Widget -Shows the contribution graph, similar to the one on the github profile page: +The widget is inspired by the https://github-contributions.now.sh/ and relies on it's API. -![screenshot](./screenshot.jpg) +It shows the contribution graph, similar to the one on the github profile page: ![screenshot](./screenshots/screenshot.jpg) + +You might wonder what could be the reason to have your github's contributions in front of you all day long? The more you contribute, the nicer widget looks! Check out [Thomashighbaugh](https://github.com/Thomashighbaugh)'s graph: + +![](./screenshots/Thomashighbaugh.png) ## Customization @@ -10,20 +14,37 @@ It is possible to customize the widget by providing a table with all or some of | Name | Default | Description | |---|---|---| -| `username` | 'streetturtle' | Username | +| `username` | `streetturtle` | GitHub username | | `days` | `365` | Number of days in the past, more days - wider the widget | -| `empty_color` | `beautiful.bg_normal` | Color of the days with no contributions | +| `color_of_empty_cells` | Theme's default | Color of the days with no contributions | | `with_border` | `true` | Should the graph contains border or not | | `margin_top` | `1` | Top margin | +| `theme` | `standard` | Color theme of the graph, see below | -Few more screenshots: +_Note:_ widget height is 21px (7 rows of 3x3 cells). So it would look nice on the wibar of 22-24px height. + +### Themes + +Following themes are available: + +| Theme name | Preview | +|---|---| +| standard | ![standard](./screenshots/standard.png) | +| classic | ![classic](./screenshots/classic.png) | +| teal | ![teal](./screenshots/teal.png) | +| leftpad | ![leftpad](./screenshots/leftpad.png) | +| dracula | ![dracula](./screenshots/dracula.png) | +| pink | ![pink](./screenshots/pink.png) | + +To add a new theme, simply add a new entry in `themes` table (themes.lua) with the colors of your theme. + +### Screenshots 1000 days, with border: -![screenshot1](./screenshot1.jpg) +![screenshot1](./screenshots/screenshot1.jpg) 365 days, no border: -![screenshot2](./screenshot2.jpg) - +![screenshot2](./screenshots/screenshot2.jpg) ## Installation diff --git a/github-contributions-widget/github-contributions-widget.lua b/github-contributions-widget/github-contributions-widget.lua index 7da2b48..b462299 100644 --- a/github-contributions-widget/github-contributions-widget.lua +++ b/github-contributions-widget/github-contributions-widget.lua @@ -9,12 +9,11 @@ ------------------------------------------------- local awful = require("awful") +local naughty = require("naughty") local wibox = require("wibox") -local beautiful = require("beautiful") +local widget_themes = require("awesome-wm-widgets.github-contributions-widget.themes") local GET_CONTRIBUTIONS_CMD = [[bash -c "curl -s https://github-contributions.now.sh/api/v1/%s | jq -r '[.contributions[] | select ( .date | strptime(\"%%Y-%%m-%%d\") | mktime < now)][:%s]| .[].color'"]] --- in case github-contributions.now.sh stops working contributions can be scrapped from the github.com with the command below. Note that the order is reversed. -local GET_CONTRIBUTIONS_CMD_FALLBACK = [[bash -c "curl -s https://github.com/users/%s/contributions | grep -o '\" fill=\"\#[0-9a-fA-F]\{6\}\" da' | grep -o '\#[0-9a-fA-F]\{6\}'"]] local github_contributions_widget = wibox.widget{ reflection = { @@ -24,13 +23,12 @@ local github_contributions_widget = wibox.widget{ widget = wibox.container.mirror } -local color_dict = { - color_calendar_graph_day_L4_bg = '#216e39', - color_calendar_graph_day_L3_bg = '#239a3b', - color_calendar_graph_day_L2_bg = '#7bc96f', - color_calendar_graph_day_L1_bg = '#c6e48b', - color_calendar_graph_day_bg = '#ebedf0', -} +local function show_warning(message) + naughty.notify{ + preset = naughty.config.presets.critical, + title = 'Github Contributions Widget', + text = message} +end local function worker(args) @@ -38,18 +36,26 @@ local function worker(args) local username = args.username or 'streetturtle' local days = args.days or 365 - local empty_color = args.empty_color or beautiful.bg_normal + local color_of_empty_cells = args.color_of_empty_cells local with_border = args.with_border local margin_top = args.margin_top or 1 + local theme = args.theme or 'standard' + + if widget_themes[theme] == nil then + show_warning('Theme ' .. theme .. ' does not exist') + theme = 'standard' + end if with_border == nil then with_border = true end local function hex2rgb(hex) - if hex == '#ebedf0' then hex = empty_color end - hex = tostring(hex):gsub("#","") - return tonumber("0x" .. hex:sub(1, 2)), - tonumber("0x" .. hex:sub(3, 4)), - tonumber("0x" .. hex:sub(5, 6)) + if color_of_empty_cells ~= nil and hex == widget_themes[theme]['color_calendar_graph_day_bg'] then + hex = color_of_empty_cells + end + hex = tostring(hex):gsub('#','') + return tonumber('0x' .. hex:sub(1, 2)), + tonumber('0x' .. hex:sub(3, 4)), + tonumber('0x' .. hex:sub(5, 6)) end local function get_square(color) @@ -70,9 +76,9 @@ local function worker(args) local col = {layout = wibox.layout.fixed.vertical} local row = {layout = wibox.layout.fixed.horizontal} - local a = 6 - os.date('%w') + local a = 5 - os.date('%w') for i = 0, a do - table.insert(col, get_square('#ebedf0')) + table.insert(col, get_square(color_of_empty_cells)) end local update_widget = function(widget, stdout, _, _, _) @@ -81,7 +87,7 @@ local function worker(args) table.insert(row, col) col = {layout = wibox.layout.fixed.vertical} end - table.insert(col, get_square(color_dict[colors:match('var%(%-%-(.*)%)'):gsub('-', '_')])) + table.insert(col, get_square(widget_themes[theme][colors:match('var%(%-%-(.*)%)'):gsub('-', '_')])) a = a + 1 end github_contributions_widget:setup( diff --git a/github-contributions-widget/screenshots/Thomashighbaugh.png b/github-contributions-widget/screenshots/Thomashighbaugh.png new file mode 100644 index 0000000000000000000000000000000000000000..b31245b78ff64b39ba7ff07756627581ab1b69f9 GIT binary patch literal 384 zcmV-`0e}99P){6xhPTF`8FXQ2C(otkbvpW6jd7pG zeTu$3Zon!*wW9aS&@V&bdA653qRSAr#}QqwANl9+r3R1{gFxXo1X{8o-^}N1&e>#j zYmm#dqUU=GpONjXCf>&7QUgGsfIxFLd@{ATH@v!b8}Vjb@-Am1@qX@?8UO+X1X`(x z8Z?f2O;~HdD#@~=DjU>ekv(LffItC(wl7CV_Ecqmvylq0){{Dl01`^LfItC(*0q37 zieww=pHrd%>vtK5g z?#iKK9@m*&bPcC8 zP86R=-<;Hm%6VPwultR{xtD8*FhPMup}$pCwfICLz*P$Ua^w=RNIlvAbnDK-aYW1+ zS+sSKxKST=4_6Z-M@h%D&T)5>8sT@|mZ&~rVhZk6S> k^$*@QU{UBe6bEeb2hqK@JjM0sApigX07*qoM6N<$g8bIo{cTuyO5 zpX1i!Q||!)eHf&GOQ+rKw7VCZ=EK8$ct|*4ps5l1gR(y;uNt%Kj#m>Xr3ImbyArzl zuqW@8L1D*YdMu{#QuAY$1)s`*8M+Ys_dBy|<8il_8*}RV4kqDqp=(e`mZsvBRDIfNLAY{7q)x&B^ zUYyD_N4eO~VPHVYeg!KY*4iu(p|Q5c1O*y}{2z)cf822vemu>*f&v457bGCX4T1Bm$@t`ssW^7G&ya0j*0;oDV-bVe3C4T;r`3m2F1tuB|-D)zAu3Kc(Vms`mXJ}_V3WT z%K0t!3!?bx?`sl_qdg7-3Df#n5q zkFdQ69S}M|wH3PR%(vwXm;8%N&4oFtgvTc0MDX!Y98V%bNuHy+J3f_~cgkIZ= z&;g+X+(_tmB=ZwEck$VNQR(}<7EL0{;?V?z4xr%&=%+X&ysUq7kAyjwICIL4>Ior^^-k%3Rdpy|!E&CkyIs6=2 z`(^DH#|vhLE+LFt7`Ibnj>~y8p;0=74u2)|c(A*#s-Upx7^Y(=ms%RLEqE^jR#;vk z_lVnz&;g+XG+Uvo&U{S1{M+!fIa~GfO7nQ!xYtdw~EFMij=l~kN1)!&V%P2Nu00000NkvXXu0mjf DcPFVW literal 0 HcmV?d00001 diff --git a/github-contributions-widget/screenshot.jpg b/github-contributions-widget/screenshots/screenshot.jpg similarity index 100% rename from github-contributions-widget/screenshot.jpg rename to github-contributions-widget/screenshots/screenshot.jpg diff --git a/github-contributions-widget/screenshot1.jpg b/github-contributions-widget/screenshots/screenshot1.jpg similarity index 100% rename from github-contributions-widget/screenshot1.jpg rename to github-contributions-widget/screenshots/screenshot1.jpg diff --git a/github-contributions-widget/screenshot2.jpg b/github-contributions-widget/screenshots/screenshot2.jpg similarity index 100% rename from github-contributions-widget/screenshot2.jpg rename to github-contributions-widget/screenshots/screenshot2.jpg diff --git a/github-contributions-widget/screenshots/standard.png b/github-contributions-widget/screenshots/standard.png new file mode 100644 index 0000000000000000000000000000000000000000..e10479aee0a2d75f977f4b06c38f4739f49b8c8d GIT binary patch literal 408 zcmV;J0cZY+P)GCu}ukA(X zfY1SMB=kE{_z9f5_-wzZ^nG57CX;3HXaYh9(C`Het8&JbMNOdq0000pZTr;{`KAmoV+iv@fT|9GCNGLZfsD9sWw_@nCmfRY75W82T`jOD&Dr7QB}MD=e>& zd&KQU=z!1xnyt`PXTB|Gxa40HYA()EB|J6}XM#_M(s(ivO7a}l-4Qw