what the fuck
This commit is contained in:
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -7,3 +7,9 @@
|
||||
[submodule "common/.config/awesome/plugins/rubato"]
|
||||
path = common/.config/awesome/plugins/rubato
|
||||
url = https://github.com/andOrlando/rubato
|
||||
[submodule "common/.config/awesome/json.lua"]
|
||||
path = common/.config/awesome/json/
|
||||
url = https://github.com/rxi/json.lua
|
||||
[submodule "common/.config/awesome/json"]
|
||||
path = common/.config/awesome/json
|
||||
url = https://github.com/rxi/json.lua
|
||||
|
||||
12
arch.os
12
arch.os
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
#
|
||||
# Dev utilsv
|
||||
yay -S neovim-git nvm wezterm ranger ripgrep zsh curl exa
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
@@ -7,11 +7,11 @@ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/too
|
||||
# WM Deps
|
||||
yay -S awesome-git
|
||||
yay -S picom-pijulis-git
|
||||
yay -S ttf-twemoji xorg-xbacklight xidlehook sysstat i3blocks mpris-ctl flameshot perl rofi
|
||||
yay -S i3exit arc-icon-theme ttf-twemoji xorg-xbacklight xidlehook sysstat i3blocks mpris-ctl flameshot perl rofi
|
||||
|
||||
mkdir -p ~/.local/share/fonts
|
||||
cd ~/.local/share/fonts
|
||||
curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/HEAD/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
|
||||
curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/HEAD/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
|
||||
cd ~
|
||||
|
||||
# Tmux
|
||||
@@ -19,6 +19,12 @@ yay -S tmux
|
||||
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
|
||||
tmux source ~/.tmux.conf
|
||||
|
||||
git clone https://gist.github.com/fa6258f3ff7b17747ee3.git
|
||||
cd ./fa6258f3ff7b17747ee3
|
||||
chmod +x sp
|
||||
# This widget will work by default if the binary is in the system PATH
|
||||
sudo cp ./sp /usr/local/bin/
|
||||
|
||||
# Audio
|
||||
yay -S pulseaudio-equalizer-ladspa mpris-ctl
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ Ben = {
|
||||
},
|
||||
fonts = {
|
||||
normal = "DejaVu Sans Mono 12",
|
||||
small = "DejaVu Sans Mono 9",
|
||||
monospace = "DejaVu Sans Mono 12",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -36,6 +36,6 @@ widgets.clock = wibox.widget({
|
||||
widgets.separator = wibox.widget.separator()
|
||||
|
||||
widgets.systray = wibox.widget.systray()
|
||||
widgets.systray:set_base_size(16)
|
||||
widgets.systray:set_base_size(30)
|
||||
|
||||
return widgets
|
||||
|
||||
@@ -126,7 +126,7 @@ shadow-exclude = [
|
||||
# Fade windows in/out when opening/closing and when opacity changes,
|
||||
# unless no-fading-openclose is used.
|
||||
# fading = false
|
||||
fading = true;
|
||||
fading = false;
|
||||
|
||||
# Opacity change between steps while fading in. (0.01 - 1.0, defaults to 0.028)
|
||||
# fade-in-step = 0.028
|
||||
@@ -159,7 +159,7 @@ fade-exclude = [
|
||||
|
||||
# Opacity of inactive windows. (0.1 - 1.0, defaults to 1.0)
|
||||
# inactive-opacity = 1
|
||||
inactive-opacity = 0.95;
|
||||
inactive-opacity = 0.9;
|
||||
|
||||
# Opacity of window titlebars and borders. (0.1 - 1.0, disabled by default)
|
||||
# frame-opacity = 1.0
|
||||
|
||||
@@ -4,7 +4,13 @@ local wibox = require("wibox")
|
||||
local create_tags = require("core.tags").create_tags
|
||||
local widgets = require("ben.widgets")
|
||||
|
||||
local batteryarc_widget = require("awesome-wm-widgets.batteryarc-widget.batteryarc")
|
||||
local logout_menu_widget = require("awesome-wm-widgets.logout-menu-widget.logout-menu")
|
||||
local battery_widget = require("awesome-wm-widgets.battery-widget.battery")
|
||||
local cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget")
|
||||
local ram_widget = require("awesome-wm-widgets.ram-widget.ram-widget")
|
||||
local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify")
|
||||
local fs_widget = require("awesome-wm-widgets.fs-widget.fs-widget")
|
||||
local weather_widget = require("awesome-wm-widgets.weather-widget.weather")
|
||||
|
||||
awful.screen.connect_for_each_screen(function(screen)
|
||||
local tags = create_tags(screen)
|
||||
@@ -13,9 +19,9 @@ awful.screen.connect_for_each_screen(function(screen)
|
||||
screen = screen,
|
||||
filter = awful.widget.taglist.filter.all,
|
||||
buttons = gears.table.join(
|
||||
awful.button({}, 1, function(tag)
|
||||
tag:view_only()
|
||||
end)
|
||||
awful.button({}, 1, function(tag)
|
||||
tag:view_only()
|
||||
end)
|
||||
),
|
||||
})
|
||||
|
||||
@@ -26,25 +32,82 @@ awful.screen.connect_for_each_screen(function(screen)
|
||||
|
||||
screen.wibar:setup({
|
||||
layout = wibox.layout.align.horizontal,
|
||||
expand = "none",
|
||||
{
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
screen.taglist,
|
||||
},
|
||||
widgets.separator,
|
||||
{
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
widgets.systray,
|
||||
batteryarc_widget({
|
||||
font = Ben.fonts.normal,
|
||||
show_current_level = true,
|
||||
charging_color = Ben.colors.green,
|
||||
low_level_color = Ben.colors.red,
|
||||
medium_level_color = Ben.colors.yellow,
|
||||
notification_position = "bottom_right",
|
||||
warning_msg_title = "Battery is dying",
|
||||
}),
|
||||
widgets.clock,
|
||||
widgets.launcher,
|
||||
{
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
spotify_widget({
|
||||
font = Ben.fonts.normal,
|
||||
play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg',
|
||||
pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg',
|
||||
dim_when_paused = true,
|
||||
dim_opacity = 0.5,
|
||||
max_length = -1,
|
||||
show_tooltip = true,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
left = 20,
|
||||
widgets.systray,
|
||||
},
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
left = 20,
|
||||
fs_widget()
|
||||
},
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
left = 20,
|
||||
battery_widget({
|
||||
font = Ben.fonts.normal,
|
||||
show_current_level = true,
|
||||
charging_color = Ben.colors.green,
|
||||
low_level_color = Ben.colors.red,
|
||||
medium_level_color = Ben.colors.yellow,
|
||||
show_notification_mode = "on_click",
|
||||
notification_position = "top_right",
|
||||
warning_msg_title = "Battery is dying",
|
||||
size = 25,
|
||||
}),
|
||||
},
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
left = 20,
|
||||
cpu_widget(),
|
||||
},
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
left = 20,
|
||||
ram_widget({
|
||||
widget_height = 50,
|
||||
widget_width = 30,
|
||||
color_used = Ben.colors.red,
|
||||
color_free = Ben.colors.green,
|
||||
widget_show_buf = false,
|
||||
}),
|
||||
},
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
widgets.clock,
|
||||
},
|
||||
{
|
||||
layout = wibox.container.margin,
|
||||
logout_menu_widget({
|
||||
onlock = function() awful.spawn.with_shell('i3exit lock') end,
|
||||
onsuspend = function()
|
||||
awful.spawn.with_shell('i3exit suspend')
|
||||
end
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
local layout = require("awful").layout
|
||||
|
||||
layout.layouts = {
|
||||
layout.suit.tile.left,
|
||||
layout.suit.fair,
|
||||
layout.suit.floating,
|
||||
layout.suit.spiral.dwindle,
|
||||
layout.suit.floating,
|
||||
layout.suit.tile,
|
||||
layout.suit.tile.left,
|
||||
layout.suit.tile.bottom,
|
||||
layout.suit.tile.top,
|
||||
layout.suit.fair,
|
||||
layout.suit.fair.horizontal,
|
||||
layout.suit.spiral,
|
||||
layout.suit.max,
|
||||
layout.suit.max.fullscreen,
|
||||
layout.suit.magnifier,
|
||||
layout.suit.corner.nw,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ ruled.notification.connect_signal("request::rules", function()
|
||||
rule = {},
|
||||
properties = {
|
||||
screen = awful.screen.preferred,
|
||||
implicit_timeout = 5,
|
||||
implicit_timeout = 2,
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
@@ -4,7 +4,7 @@ local fonts = Ben.fonts
|
||||
|
||||
return {
|
||||
-- The Awesome icon path
|
||||
awesome_icon = "/mnt/mass/pictures/Schnose/schnose.png",
|
||||
awesome_icon = "",
|
||||
-- The default focused element background color
|
||||
bg_focus = colors.base,
|
||||
-- The default minimized element background color
|
||||
@@ -38,19 +38,19 @@ return {
|
||||
-- The border color when the client has the urgent property set
|
||||
border_color_urgent = colors.red,
|
||||
-- The fallback border width when nothing else is set
|
||||
border_width = 2,
|
||||
border_width = 0,
|
||||
-- The client border width for the active client
|
||||
border_width_active = 2,
|
||||
border_width_active = 0,
|
||||
-- The fallback border width when the client is floating
|
||||
border_width_floating = 4,
|
||||
border_width_floating = 0,
|
||||
-- The client border width for the active floating client
|
||||
border_width_floating_active = 4,
|
||||
border_width_floating_active = 0,
|
||||
-- The client border width for the new floating clients
|
||||
border_width_floating_new = 4,
|
||||
border_width_floating_new = 0,
|
||||
-- The client border width for the normal floating clients
|
||||
border_width_floating_normal = 4,
|
||||
border_width_floating_normal = 0,
|
||||
-- The client border width for the urgent floating clients
|
||||
border_width_floating_urgent = 4,
|
||||
border_width_floating_urgent = 0,
|
||||
-- The client border width for the fullscreen clients
|
||||
border_width_fullscreen = 0,
|
||||
-- The client border width for the active fullscreen client
|
||||
@@ -60,7 +60,7 @@ return {
|
||||
-- The client border width for the normal fullscreen clients
|
||||
border_width_fullscreen_normal = 0,
|
||||
-- The client border width for the urgent fullscreen clients
|
||||
border_width_fullscreen_urgent = 2,
|
||||
border_width_fullscreen_urgent = 0,
|
||||
-- The fallback border width when the client is maximized
|
||||
border_width_maximized = 0,
|
||||
-- The client border width for the active maximized client
|
||||
@@ -70,13 +70,13 @@ return {
|
||||
-- The client border width for the normal maximized clients
|
||||
border_width_maximized_normal = 0,
|
||||
-- The client border width for the urgent maximized clients
|
||||
border_width_maximized_urgent = 2,
|
||||
border_width_maximized_urgent = 0,
|
||||
-- The client border width for the new clients
|
||||
border_width_new = 2,
|
||||
-- The client border width for the normal clients
|
||||
border_width_normal = 2,
|
||||
border_width_normal = 0,
|
||||
-- The client border width for the urgent clients
|
||||
border_width_urgent = 2,
|
||||
border_width_urgent = 0,
|
||||
-- The calendar font
|
||||
calendar_font = fonts.normal,
|
||||
-- Format the weekdays with three characters instead of two
|
||||
@@ -298,7 +298,7 @@ return {
|
||||
-- The urgent titlebar foreground (text) color
|
||||
titlebar_fg_urgent = colors.red,
|
||||
-- The default gap
|
||||
useless_gap = dpi(2),
|
||||
useless_gap = 0,
|
||||
-- The default wallpaper background color
|
||||
wallpaper_bg = colors.base,
|
||||
-- The default wallpaper foreground color
|
||||
@@ -312,7 +312,7 @@ return {
|
||||
-- The wibar's foreground (text) color
|
||||
wibar_fg = colors.text,
|
||||
-- The wibar's height
|
||||
wibar_height = 20,
|
||||
wibar_height = 30,
|
||||
-- If the wibar is to be on top of other windows
|
||||
wibar_ontop = false,
|
||||
}
|
||||
|
||||
1
common/.config/awesome/json
Submodule
1
common/.config/awesome/json
Submodule
Submodule common/.config/awesome/json added at dbf4b2dd2e
388
common/.config/awesome/json.lua
Normal file
388
common/.config/awesome/json.lua
Normal file
@@ -0,0 +1,388 @@
|
||||
--
|
||||
-- json.lua
|
||||
--
|
||||
-- Copyright (c) 2020 rxi
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
-- this software and associated documentation files (the "Software"), to deal in
|
||||
-- the Software without restriction, including without limitation the rights to
|
||||
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
-- of the Software, and to permit persons to whom the Software is furnished to do
|
||||
-- so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in all
|
||||
-- copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
-- SOFTWARE.
|
||||
--
|
||||
|
||||
local json = { _version = "0.1.2" }
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Encode
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local encode
|
||||
|
||||
local escape_char_map = {
|
||||
[ "\\" ] = "\\",
|
||||
[ "\"" ] = "\"",
|
||||
[ "\b" ] = "b",
|
||||
[ "\f" ] = "f",
|
||||
[ "\n" ] = "n",
|
||||
[ "\r" ] = "r",
|
||||
[ "\t" ] = "t",
|
||||
}
|
||||
|
||||
local escape_char_map_inv = { [ "/" ] = "/" }
|
||||
for k, v in pairs(escape_char_map) do
|
||||
escape_char_map_inv[v] = k
|
||||
end
|
||||
|
||||
|
||||
local function escape_char(c)
|
||||
return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
|
||||
end
|
||||
|
||||
|
||||
local function encode_nil(val)
|
||||
return "null"
|
||||
end
|
||||
|
||||
|
||||
local function encode_table(val, stack)
|
||||
local res = {}
|
||||
stack = stack or {}
|
||||
|
||||
-- Circular reference?
|
||||
if stack[val] then error("circular reference") end
|
||||
|
||||
stack[val] = true
|
||||
|
||||
if rawget(val, 1) ~= nil or next(val) == nil then
|
||||
-- Treat as array -- check keys are valid and it is not sparse
|
||||
local n = 0
|
||||
for k in pairs(val) do
|
||||
if type(k) ~= "number" then
|
||||
error("invalid table: mixed or invalid key types")
|
||||
end
|
||||
n = n + 1
|
||||
end
|
||||
if n ~= #val then
|
||||
error("invalid table: sparse array")
|
||||
end
|
||||
-- Encode
|
||||
for i, v in ipairs(val) do
|
||||
table.insert(res, encode(v, stack))
|
||||
end
|
||||
stack[val] = nil
|
||||
return "[" .. table.concat(res, ",") .. "]"
|
||||
|
||||
else
|
||||
-- Treat as an object
|
||||
for k, v in pairs(val) do
|
||||
if type(k) ~= "string" then
|
||||
error("invalid table: mixed or invalid key types")
|
||||
end
|
||||
table.insert(res, encode(k, stack) .. ":" .. encode(v, stack))
|
||||
end
|
||||
stack[val] = nil
|
||||
return "{" .. table.concat(res, ",") .. "}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function encode_string(val)
|
||||
return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"'
|
||||
end
|
||||
|
||||
|
||||
local function encode_number(val)
|
||||
-- Check for NaN, -inf and inf
|
||||
if val ~= val or val <= -math.huge or val >= math.huge then
|
||||
error("unexpected number value '" .. tostring(val) .. "'")
|
||||
end
|
||||
return string.format("%.14g", val)
|
||||
end
|
||||
|
||||
|
||||
local type_func_map = {
|
||||
[ "nil" ] = encode_nil,
|
||||
[ "table" ] = encode_table,
|
||||
[ "string" ] = encode_string,
|
||||
[ "number" ] = encode_number,
|
||||
[ "boolean" ] = tostring,
|
||||
}
|
||||
|
||||
|
||||
encode = function(val, stack)
|
||||
local t = type(val)
|
||||
local f = type_func_map[t]
|
||||
if f then
|
||||
return f(val, stack)
|
||||
end
|
||||
error("unexpected type '" .. t .. "'")
|
||||
end
|
||||
|
||||
|
||||
function json.encode(val)
|
||||
return ( encode(val) )
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Decode
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local parse
|
||||
|
||||
local function create_set(...)
|
||||
local res = {}
|
||||
for i = 1, select("#", ...) do
|
||||
res[ select(i, ...) ] = true
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
local space_chars = create_set(" ", "\t", "\r", "\n")
|
||||
local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",")
|
||||
local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u")
|
||||
local literals = create_set("true", "false", "null")
|
||||
|
||||
local literal_map = {
|
||||
[ "true" ] = true,
|
||||
[ "false" ] = false,
|
||||
[ "null" ] = nil,
|
||||
}
|
||||
|
||||
|
||||
local function next_char(str, idx, set, negate)
|
||||
for i = idx, #str do
|
||||
if set[str:sub(i, i)] ~= negate then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return #str + 1
|
||||
end
|
||||
|
||||
|
||||
local function decode_error(str, idx, msg)
|
||||
local line_count = 1
|
||||
local col_count = 1
|
||||
for i = 1, idx - 1 do
|
||||
col_count = col_count + 1
|
||||
if str:sub(i, i) == "\n" then
|
||||
line_count = line_count + 1
|
||||
col_count = 1
|
||||
end
|
||||
end
|
||||
error( string.format("%s at line %d col %d", msg, line_count, col_count) )
|
||||
end
|
||||
|
||||
|
||||
local function codepoint_to_utf8(n)
|
||||
-- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa
|
||||
local f = math.floor
|
||||
if n <= 0x7f then
|
||||
return string.char(n)
|
||||
elseif n <= 0x7ff then
|
||||
return string.char(f(n / 64) + 192, n % 64 + 128)
|
||||
elseif n <= 0xffff then
|
||||
return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128)
|
||||
elseif n <= 0x10ffff then
|
||||
return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128,
|
||||
f(n % 4096 / 64) + 128, n % 64 + 128)
|
||||
end
|
||||
error( string.format("invalid unicode codepoint '%x'", n) )
|
||||
end
|
||||
|
||||
|
||||
local function parse_unicode_escape(s)
|
||||
local n1 = tonumber( s:sub(1, 4), 16 )
|
||||
local n2 = tonumber( s:sub(7, 10), 16 )
|
||||
-- Surrogate pair?
|
||||
if n2 then
|
||||
return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000)
|
||||
else
|
||||
return codepoint_to_utf8(n1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function parse_string(str, i)
|
||||
local res = ""
|
||||
local j = i + 1
|
||||
local k = j
|
||||
|
||||
while j <= #str do
|
||||
local x = str:byte(j)
|
||||
|
||||
if x < 32 then
|
||||
decode_error(str, j, "control character in string")
|
||||
|
||||
elseif x == 92 then -- `\`: Escape
|
||||
res = res .. str:sub(k, j - 1)
|
||||
j = j + 1
|
||||
local c = str:sub(j, j)
|
||||
if c == "u" then
|
||||
local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1)
|
||||
or str:match("^%x%x%x%x", j + 1)
|
||||
or decode_error(str, j - 1, "invalid unicode escape in string")
|
||||
res = res .. parse_unicode_escape(hex)
|
||||
j = j + #hex
|
||||
else
|
||||
if not escape_chars[c] then
|
||||
decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string")
|
||||
end
|
||||
res = res .. escape_char_map_inv[c]
|
||||
end
|
||||
k = j + 1
|
||||
|
||||
elseif x == 34 then -- `"`: End of string
|
||||
res = res .. str:sub(k, j - 1)
|
||||
return res, j + 1
|
||||
end
|
||||
|
||||
j = j + 1
|
||||
end
|
||||
|
||||
decode_error(str, i, "expected closing quote for string")
|
||||
end
|
||||
|
||||
|
||||
local function parse_number(str, i)
|
||||
local x = next_char(str, i, delim_chars)
|
||||
local s = str:sub(i, x - 1)
|
||||
local n = tonumber(s)
|
||||
if not n then
|
||||
decode_error(str, i, "invalid number '" .. s .. "'")
|
||||
end
|
||||
return n, x
|
||||
end
|
||||
|
||||
|
||||
local function parse_literal(str, i)
|
||||
local x = next_char(str, i, delim_chars)
|
||||
local word = str:sub(i, x - 1)
|
||||
if not literals[word] then
|
||||
decode_error(str, i, "invalid literal '" .. word .. "'")
|
||||
end
|
||||
return literal_map[word], x
|
||||
end
|
||||
|
||||
|
||||
local function parse_array(str, i)
|
||||
local res = {}
|
||||
local n = 1
|
||||
i = i + 1
|
||||
while 1 do
|
||||
local x
|
||||
i = next_char(str, i, space_chars, true)
|
||||
-- Empty / end of array?
|
||||
if str:sub(i, i) == "]" then
|
||||
i = i + 1
|
||||
break
|
||||
end
|
||||
-- Read token
|
||||
x, i = parse(str, i)
|
||||
res[n] = x
|
||||
n = n + 1
|
||||
-- Next token
|
||||
i = next_char(str, i, space_chars, true)
|
||||
local chr = str:sub(i, i)
|
||||
i = i + 1
|
||||
if chr == "]" then break end
|
||||
if chr ~= "," then decode_error(str, i, "expected ']' or ','") end
|
||||
end
|
||||
return res, i
|
||||
end
|
||||
|
||||
|
||||
local function parse_object(str, i)
|
||||
local res = {}
|
||||
i = i + 1
|
||||
while 1 do
|
||||
local key, val
|
||||
i = next_char(str, i, space_chars, true)
|
||||
-- Empty / end of object?
|
||||
if str:sub(i, i) == "}" then
|
||||
i = i + 1
|
||||
break
|
||||
end
|
||||
-- Read key
|
||||
if str:sub(i, i) ~= '"' then
|
||||
decode_error(str, i, "expected string for key")
|
||||
end
|
||||
key, i = parse(str, i)
|
||||
-- Read ':' delimiter
|
||||
i = next_char(str, i, space_chars, true)
|
||||
if str:sub(i, i) ~= ":" then
|
||||
decode_error(str, i, "expected ':' after key")
|
||||
end
|
||||
i = next_char(str, i + 1, space_chars, true)
|
||||
-- Read value
|
||||
val, i = parse(str, i)
|
||||
-- Set
|
||||
res[key] = val
|
||||
-- Next token
|
||||
i = next_char(str, i, space_chars, true)
|
||||
local chr = str:sub(i, i)
|
||||
i = i + 1
|
||||
if chr == "}" then break end
|
||||
if chr ~= "," then decode_error(str, i, "expected '}' or ','") end
|
||||
end
|
||||
return res, i
|
||||
end
|
||||
|
||||
|
||||
local char_func_map = {
|
||||
[ '"' ] = parse_string,
|
||||
[ "0" ] = parse_number,
|
||||
[ "1" ] = parse_number,
|
||||
[ "2" ] = parse_number,
|
||||
[ "3" ] = parse_number,
|
||||
[ "4" ] = parse_number,
|
||||
[ "5" ] = parse_number,
|
||||
[ "6" ] = parse_number,
|
||||
[ "7" ] = parse_number,
|
||||
[ "8" ] = parse_number,
|
||||
[ "9" ] = parse_number,
|
||||
[ "-" ] = parse_number,
|
||||
[ "t" ] = parse_literal,
|
||||
[ "f" ] = parse_literal,
|
||||
[ "n" ] = parse_literal,
|
||||
[ "[" ] = parse_array,
|
||||
[ "{" ] = parse_object,
|
||||
}
|
||||
|
||||
|
||||
parse = function(str, idx)
|
||||
local chr = str:sub(idx, idx)
|
||||
local f = char_func_map[chr]
|
||||
if f then
|
||||
return f(str, idx)
|
||||
end
|
||||
decode_error(str, idx, "unexpected character '" .. chr .. "'")
|
||||
end
|
||||
|
||||
|
||||
function json.decode(str)
|
||||
if type(str) ~= "string" then
|
||||
error("expected argument of type string, got " .. type(str))
|
||||
end
|
||||
local res, idx = parse(str, next_char(str, 1, space_chars, true))
|
||||
idx = next_char(str, idx, space_chars, true)
|
||||
if idx <= #str then
|
||||
decode_error(str, idx, "trailing garbage")
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
|
||||
return json
|
||||
@@ -45,6 +45,7 @@ local nice = require("plugins.nice")
|
||||
nice({
|
||||
titlebar_color = Ben.colors.crust,
|
||||
titlebar_height = 20,
|
||||
titlebar_font = Ben.fonts.small,
|
||||
button_size = 14,
|
||||
mb_resize = nice.MB_MIDDLE,
|
||||
mb_contextmenu = nice.MB_RIGHT,
|
||||
|
||||
Reference in New Issue
Block a user