Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first version #1

Merged
merged 11 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
BasedOnStyle: Mozilla
ColumnLimit: 80
IndentWidth: 4
UseTab: Never
---
Language: Cpp
AllowShortIfStatementsOnASingleLine: Never
BreakBeforeBraces: Attach
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
DerivePointerAlignment: false
PointerAlignment: Right
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.h linguist-language=C
*.sh linguist-generated
Makefile linguist-generated
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: rodrigodornelles
27 changes: 27 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci

on:
workflow_dispatch:
push:
branches:
- main
pull_request:

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
-
run: clang-format --dry-run --Werror --verbose rgb_to_xterm256.h
-
run: clang-format --dry-run --Werror --verbose tools/pride.c

tests:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
-
run: make test
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.out
*.exe
*.zip
*.txt
!LICENSE.txt
pride
html/
latex/
DS_Store
Thumbs.db
14 changes: 14 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2024 Rodrigo Dornelles

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
11 changes: 11 additions & 0 deletions Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions rgb_to_xterm256.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
unsigned char
rgb_to_xterm256(unsigned char r, unsigned char g, unsigned char b) {

unsigned int color_id = 0;
unsigned char half_color = (r >= 0x80 && r < 0x87) << 2 |
(g >= 0x80 && g < 0x87) << 1 |
(b >= 0x80 && b < 0x87);

static const unsigned char gray_brightness[] = {
0x00, 0x08, 0x12, 0x1c, 0x26, 0x30, 0x3a, 0x44, 0x4e, 0x58, 0x5f,
0x62, 0x6c, 0x76, 0x80, 0x87, 0x8a, 0x94, 0x9e, 0xa8, 0xaf, 0xb2,
0xbc, 0xc0, 0xc6, 0xd0, 0xd7, 0xda, 0xe4, 0xee, 0xff
};

static const unsigned char gray_colors[] = {
0x00, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0x3b,
0xf1, 0xf2, 0xf3, 0xf4, 0x66, 0xf5, 0xf6, 0xf7, 0xf8, 0x91, 0xf9,
0xfa, 0x07, 0xfb, 0xfc, 0xbc, 0xfd, 0xfe, 0xff, 0x0f
};

static const unsigned char term_colors[] = { 0x04, 0x02, 0x06,
0x01, 0x05, 0x03 };

if (r == g && g == b) {
unsigned char i = 0;

while (gray_brightness[i] < r) {
i++;
}

color_id = gray_colors[i];
} else if (half_color) {
color_id = term_colors[half_color - 1];
} else {
r = ((r << 2) + r) / 255;
g = ((g << 2) + g) / 255;
b = ((b << 2) + b) / 255;
color_id = 16 + ((r << 5) + (r << 2)) + ((g << 2) + (g << 1)) + b;
}

return color_id;
}
5 changes: 5 additions & 0 deletions tests/test_dornelles.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/test_mateusgpt.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/test_rgb2xterm.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading