Skip to content

Commit

Permalink
chore: added editorconfig and did a bit of formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgeiler committed Apr 17, 2024
1 parent 4b0676d commit 1744914
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# clang-format configuration
# See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

BasedOnStyle: Google
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# clang-tidy configuration
# See: https://clang.llvm.org/extra/clang-tidy/

Checks: >-
-*,
bugprone-*,
Expand Down
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# EditorConfig configuration
# See: https://editorconfig.org

root = true

[*]
indent_style = tab
indent_size = tab
#tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[*.{json,yml,yaml,md,mdx,c,h,cpp,hpp,cc,hh}]
indent_style = space
indent_size = 2

[*.json]
insert_final_newline = false

[*.{md,mdx}]
trim_trailing_whitespace = false

[*.{lua,rockspec}]
max_line_length = 120
quote_style = single
trailing_table_separator = smart
align_continuous_assign_statement = false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Git ignore file
# See: https://git-scm.com/docs/gitignore

# IDE
.idea
.vscode
Expand Down
2 changes: 1 addition & 1 deletion demos/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local fenster = require('fenster')

-- Load image
local image_path = './' .. (
-- Get the relative directory of the script
-- Get the relative directory of the script
debug.getinfo(1, 'S').source:match('^@?(.*/)') or ''
) .. 'assets/uv.ppm'
local image = assert(io.open(image_path, 'rb'))
Expand Down
4 changes: 2 additions & 2 deletions demos/paint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local function fill(window, x, y, color, old_color)

local window_width = window.width
local window_height = window.height
local stack = {(y * window_width) + x}
local stack = { (y * window_width) + x }
while stack[1] do
local pos = table.remove(stack)
x = pos % window_width
Expand Down Expand Up @@ -150,4 +150,4 @@ while window:loop() and not window.keys[27] do
--
end
end
end
end
134 changes: 97 additions & 37 deletions demos/text-editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,30 @@ local microknight_font = {

-- Define the microknight layout
local microknight_layout = {
{0, 0}, {9, 0}, {18, 0}, {27, 0}, {36, 0}, {45, 0}, {54, 0}, {63, 0}, {72, 0}, {81, 0}, {90, 0},
{99, 0}, {108, 0}, {117, 0}, {0, 9}, {9, 9}, {18, 9}, {27, 9}, {36, 9}, {45, 9}, {54, 9}, {63, 9},
{72, 9}, {81, 9}, {90, 9}, {99, 9}, {108, 9}, {117, 9}, {0, 18}, {9, 18}, {18, 18}, {27, 18},
{36, 18}, {45, 18}, {54, 18}, {63, 18}, {72, 18}, {81, 18}, {90, 18}, {99, 18}, {108, 18}, {117, 18},
{0, 27}, {9, 27}, {18, 27}, {27, 27}, {36, 27}, {45, 27}, {54, 27}, {63, 27}, {72, 27}, {81, 27},
{90, 27}, {99, 27}, {108, 27}, {117, 27}, {0, 36}, {9, 36}, {18, 36}, {27, 36}, {36, 36}, {45, 36},
{54, 36}, {63, 36}, {72, 36}, {81, 36}, {90, 36}, {99, 36}, {108, 36}, {117, 36}, {0, 45}, {9, 45},
{18, 45}, {27, 45}, {36, 45}, {45, 45}, {54, 45}, {63, 45}, {72, 45}, {81, 45}, {90, 45}, {99, 45},
{108, 45}, {117, 45}, {0, 54}, {9, 54}, {18, 54}, {27, 54}, {36, 54}, {45, 54}, {54, 54}, {63, 54},
{72, 54}, {81, 54}, {90, 54}, {99, 54}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
{0, 0}, {108, 54}, {117, 54}, {0, 63}, {9, 63}, {18, 63}, {27, 63}, {36, 63}, {45, 63}, {54, 63},
{63, 63}, {72, 63}, {81, 63}, {90, 63}, {99, 63}, {108, 63}, {117, 63}, {0, 72}, {9, 72}, {18, 72},
{27, 72}, {36, 72}, {45, 72}, {54, 72}, {63, 72}, {72, 72}, {81, 72}, {90, 72}, {99, 72}, {108, 72},
{117, 72}, {0, 81}, {9, 81}, {18, 81}, {27, 81}, {36, 81}, {45, 81}, {54, 81}, {63, 81}, {72, 81},
{81, 81}, {90, 81}, {99, 81}, {108, 81}, {117, 81}, {0, 90}, {9, 90}, {18, 90}, {27, 90}, {36, 90},
{45, 90}, {54, 90}, {63, 90}, {72, 90}, {81, 90}, {90, 90}, {99, 90}, {108, 90}, {117, 90}, {0, 99},
{9, 99}, {18, 99}, {27, 99}, {36, 99}, {45, 99}, {54, 99}, {63, 99}, {72, 99}, {81, 99}, {90, 99},
{99, 99}, {108, 99}, {117, 99}, {0, 108}, {9, 108}, {18, 108}, {27, 108}, {36, 108}, {45, 108},
{54, 108}, {63, 108}, {72, 108}, {81, 108}, {90, 108}, {99, 108}, {108, 108}, {117, 108}, {0, 117},
{9, 117}, {18, 117}, {27, 117}, {36, 117}, {45, 117}, {54, 117}, {63, 117}, {72, 117}, {81, 117},
{ 0, 0 }, { 9, 0 }, { 18, 0 }, { 27, 0 }, { 36, 0 }, { 45, 0 }, { 54, 0 }, { 63, 0 }, { 72, 0 }, { 81, 0 }, { 90, 0 },
{ 99, 0 }, { 108, 0 }, { 117, 0 }, { 0, 9 }, { 9, 9 }, { 18, 9 }, { 27, 9 }, { 36, 9 }, { 45, 9 }, { 54, 9 },
{ 63, 9 }, { 72, 9 }, { 81, 9 }, { 90, 9 }, { 99, 9 }, { 108, 9 }, { 117, 9 }, { 0, 18 }, { 9, 18 }, { 18, 18 },
{ 27, 18 }, { 36, 18 }, { 45, 18 }, { 54, 18 }, { 63, 18 }, { 72, 18 }, { 81, 18 }, { 90, 18 }, { 99, 18 },
{ 108, 18 }, { 117, 18 }, { 0, 27 }, { 9, 27 }, { 18, 27 }, { 27, 27 }, { 36, 27 }, { 45, 27 }, { 54, 27 }, { 63, 27 },
{ 72, 27 }, { 81, 27 }, { 90, 27 }, { 99, 27 }, { 108, 27 }, { 117, 27 }, { 0, 36 }, { 9, 36 }, { 18, 36 },
{ 27, 36 }, { 36, 36 }, { 45, 36 }, { 54, 36 }, { 63, 36 }, { 72, 36 }, { 81, 36 }, { 90, 36 }, { 99, 36 },
{ 108, 36 }, { 117, 36 }, { 0, 45 }, { 9, 45 }, { 18, 45 }, { 27, 45 }, { 36, 45 }, { 45, 45 }, { 54, 45 },
{ 63, 45 }, { 72, 45 }, { 81, 45 }, { 90, 45 }, { 99, 45 }, { 108, 45 }, { 117, 45 }, { 0, 54 }, { 9, 54 }, { 18, 54 },
{ 27, 54 }, { 36, 54 }, { 45, 54 }, { 54, 54 }, { 63, 54 },
{ 72, 54 }, { 81, 54 }, { 90, 54 }, { 99, 54 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
{ 0, 0 }, { 0, 0 }, { 108, 54 }, { 117, 54 }, { 0, 63 }, { 9, 63 }, { 18, 63 }, { 27, 63 }, { 36, 63 }, { 45, 63 },
{ 54, 63 }, { 63, 63 }, { 72, 63 }, { 81, 63 }, { 90, 63 }, { 99, 63 }, { 108, 63 }, { 117, 63 }, { 0, 72 }, { 9, 72 },
{ 18, 72 }, { 27, 72 }, { 36, 72 }, { 45, 72 }, { 54, 72 }, { 63, 72 }, { 72, 72 }, { 81, 72 }, { 90, 72 }, { 99, 72 },
{ 108, 72 }, { 117, 72 }, { 0, 81 }, { 9, 81 }, { 18, 81 }, { 27, 81 }, { 36, 81 }, { 45, 81 }, { 54, 81 }, { 63, 81 },
{ 72, 81 }, { 81, 81 }, { 90, 81 }, { 99, 81 }, { 108, 81 }, { 117, 81 }, { 0, 90 }, { 9, 90 }, { 18, 90 },
{ 27, 90 }, { 36, 90 }, { 45, 90 }, { 54, 90 }, { 63, 90 }, { 72, 90 }, { 81, 90 }, { 90, 90 }, { 99, 90 },
{ 108, 90 }, { 117, 90 }, { 0, 99 }, { 9, 99 }, { 18, 99 }, { 27, 99 }, { 36, 99 }, { 45, 99 }, { 54, 99 }, { 63, 99 },
{ 72, 99 }, { 81, 99 }, { 90, 99 }, { 99, 99 }, { 108, 99 }, { 117, 99 }, { 0, 108 }, { 9, 108 }, { 18, 108 },
{ 27, 108 }, { 36, 108 }, { 45, 108 }, { 54, 108 }, { 63, 108 }, { 72, 108 }, { 81, 108 }, { 90, 108 }, { 99, 108 },
{ 108, 108 }, { 117, 108 }, { 0, 117 }, { 9, 117 }, { 18, 117 }, { 27, 117 }, { 36, 117 }, { 45, 117 }, { 54, 117 },
{ 63, 117 }, { 72, 117 }, { 81, 117 },
}

-- Calculate the microknight texture
Expand Down Expand Up @@ -215,19 +217,77 @@ local escape_key = 27
local enter_key = 10
local backspace_key = 8
local character_keys = {
[' '] = 32, ["'"] = 39, [','] = 44, ['-'] = 45, ['.'] = 46, ['/'] = 47,
['0'] = 48, ['1'] = 49, ['2'] = 50, ['3'] = 51, ['4'] = 52, ['5'] = 53,
['6'] = 54, ['7'] = 55, ['8'] = 56, ['9'] = 57, [';'] = 59, ['='] = 61,
a = 65, b = 66, c = 67, d = 68, e = 69, f = 70, g = 71, h = 72, i = 73,
j = 74, k = 75, l = 76, m = 77, n = 78, o = 79, p = 80, q = 81, r = 82,
s = 83, t = 84, u = 85, v = 86, w = 87, x = 88, y = 89, z = 90, ['['] = 91,
['\\'] = 92, [']'] = 93, ['`'] = 96,
[' '] = 32,
["'"] = 39,
[','] = 44,
['-'] = 45,
['.'] = 46,
['/'] = 47,
['0'] = 48,
['1'] = 49,
['2'] = 50,
['3'] = 51,
['4'] = 52,
['5'] = 53,
['6'] = 54,
['7'] = 55,
['8'] = 56,
['9'] = 57,
[';'] = 59,
['='] = 61,
a = 65,
b = 66,
c = 67,
d = 68,
e = 69,
f = 70,
g = 71,
h = 72,
i = 73,
j = 74,
k = 75,
l = 76,
m = 77,
n = 78,
o = 79,
p = 80,
q = 81,
r = 82,
s = 83,
t = 84,
u = 85,
v = 86,
w = 87,
x = 88,
y = 89,
z = 90,
['['] = 91,
['\\'] = 92,
[']'] = 93,
['`'] = 96,
}
local character_uppercase_map = {
["'"] = '"', [','] = '<', ['-'] = '_', ['.'] = '>', ['/'] = '?', ['1'] = '!',
['2'] = '@', ['3'] = '#', ['4'] = '$', ['5'] = '%', ['6'] = '^', ['7'] = '&',
['8'] = '*', ['9'] = '(', ['0'] = ')', [';'] = ':', ['='] = '+', ['['] = '{',
['\\'] = '|', [']'] = '}', ['`'] = '~',
["'"] = '"',
[','] = '<',
['-'] = '_',
['.'] = '>',
['/'] = '?',
['1'] = '!',
['2'] = '@',
['3'] = '#',
['4'] = '$',
['5'] = '%',
['6'] = '^',
['7'] = '&',
['8'] = '*',
['9'] = '(',
['0'] = ')',
[';'] = ':',
['='] = '+',
['['] = '{',
['\\'] = '|',
[']'] = '}',
['`'] = '~',
}

-- Text settings
Expand All @@ -247,9 +307,9 @@ local window = fenster.open(window_width, window_height, 'Text Demo')
-- Draw instructions
draw_text(
window,
'Type anything' ..
string.rep(' ', max_text_line_length - 30) ..
'Press ESC to exit',
'Type anything'
.. string.rep(' ', max_text_line_length - 30)
.. 'Press ESC to exit',
text_offset_x,
text_offset_y + text_line_height * 0
)
Expand All @@ -261,7 +321,7 @@ draw_text(
)

-- Main loop
local typed_text_lines = {''}
local typed_text_lines = { '' }
local curr_line = 1
while window:loop() and not window.keys[escape_key] do
local keys = window.keys
Expand Down
2 changes: 1 addition & 1 deletion fenster-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ build = {
test = {
type = 'busted',
flags = '--verbose',
}
}
28 changes: 14 additions & 14 deletions spec/fenster_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("fenster", function()
describe('fenster', function()
local fenster = require('fenster')

describe('fenster.open(...)', function()
Expand Down Expand Up @@ -191,15 +191,15 @@ describe("fenster", function()
end)

it('should convert a color to r/g/b', function()
assert.is_same({fenster.rgb(0x000000)}, {0, 0, 0})
assert.is_same({fenster.rgb(0x0000ff)}, {0, 0, 255})
assert.is_same({fenster.rgb(0x00ff00)}, {0, 255, 0})
assert.is_same({fenster.rgb(0x00ffff)}, {0, 255, 255})
assert.is_same({fenster.rgb(0xff0000)}, {255, 0, 0})
assert.is_same({fenster.rgb(0xff00ff)}, {255, 0, 255})
assert.is_same({fenster.rgb(0xffff00)}, {255, 255, 0})
assert.is_same({fenster.rgb(0xffffff)}, {255, 255, 255})
assert.is_same({fenster.rgb(0xbeef99)}, {190, 239, 153})
assert.is_same({ fenster.rgb(0x000000) }, { 0, 0, 0 })
assert.is_same({ fenster.rgb(0x0000ff) }, { 0, 0, 255 })
assert.is_same({ fenster.rgb(0x00ff00) }, { 0, 255, 0 })
assert.is_same({ fenster.rgb(0x00ffff) }, { 0, 255, 255 })
assert.is_same({ fenster.rgb(0xff0000) }, { 255, 0, 0 })
assert.is_same({ fenster.rgb(0xff00ff) }, { 255, 0, 255 })
assert.is_same({ fenster.rgb(0xffff00) }, { 255, 255, 0 })
assert.is_same({ fenster.rgb(0xffffff) }, { 255, 255, 255 })
assert.is_same({ fenster.rgb(0xbeef99) }, { 190, 239, 153 })
end)

it('should throw when r/g/b are not integers', function()
Expand Down Expand Up @@ -314,7 +314,7 @@ describe("fenster", function()
end)
end)

describe('window:set(...) / fenster.set(...)', function ()
describe('window:set(...) / fenster.set(...)', function()
it('should throw when no arguments were given when not using as method', function()
assert.has_errors(function() fenster.set() end)
end)
Expand Down Expand Up @@ -425,7 +425,7 @@ describe("fenster", function()
end)
end)

describe('window:get(...) / fenster.get(...)', function ()
describe('window:get(...) / fenster.get(...)', function()
it('should throw when no arguments were given when not using as method', function()
assert.has_errors(function() fenster.get() end)
end)
Expand Down Expand Up @@ -502,7 +502,7 @@ describe("fenster", function()
end)
end)

describe('window:clear(...) / fenster.clear(...)', function ()
describe('window:clear(...) / fenster.clear(...)', function()
it('should throw when no arguments were given when not using as method', function()
assert.has_errors(function() fenster.clear() end)
end)
Expand Down Expand Up @@ -719,4 +719,4 @@ describe("fenster", function()
assert.is_equal(window.targetfps, 30)
end)
end)
end)
end)

0 comments on commit 1744914

Please sign in to comment.