Skip to content

Commit f1e7dca

Browse files
committed
First commit.
0 parents  commit f1e7dca

File tree

6 files changed

+262
-0
lines changed

6 files changed

+262
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
.dart_tool/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# gitmoji

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

bin/gitmoji.dart

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import 'dart:convert';
2+
import 'dart:io' as io;
3+
import 'dart:math';
4+
import 'package:http/http.dart' as http;
5+
6+
class GitMoji {
7+
final String emoji;
8+
final String entity;
9+
final String code;
10+
final String description;
11+
final String name;
12+
final String? semver;
13+
14+
GitMoji({
15+
required this.emoji,
16+
required this.entity,
17+
required this.code,
18+
required this.description,
19+
required this.name,
20+
required this.semver,
21+
});
22+
23+
@override
24+
String toString() => '$emoji $description';
25+
}
26+
27+
void main(List<String> arguments) async {
28+
final out = io.stdout;
29+
final stdin = io.stdin;
30+
final columns = out.terminalColumns;
31+
final lineCount = 5;
32+
final marker = '=>';
33+
final emptyMarker = ''.padRight(marker.length);
34+
var selected = 0;
35+
var search = StringBuffer();
36+
37+
final response = await http.get(
38+
Uri.parse(
39+
'https://raw.githubusercontent.com/carloscuesta/gitmoji/refs/heads/master/packages/gitmojis/src/gitmojis.json',
40+
),
41+
);
42+
43+
final body = jsonDecode(response.body);
44+
45+
out.writeln('Status: ${response.statusCode}');
46+
47+
final List<dynamic> list = body['gitmojis'];
48+
49+
final List<GitMoji> gitmojis = list.map((item) {
50+
final map = item as Map<String, dynamic>;
51+
return GitMoji(
52+
emoji: map['emoji'].toString(),
53+
entity: map['entity'].toString(),
54+
code: map['code'].toString(),
55+
description: map['description'].toString(),
56+
name: map['name'].toString(),
57+
semver: map['semver']?.toString(),
58+
);
59+
}).toList();
60+
61+
out.writeln('GitMojis: ${gitmojis.length}');
62+
63+
out.writeln('Columns: ${out.terminalColumns}');
64+
65+
stdin.lineMode = false;
66+
stdin.echoMode = false;
67+
68+
while (true) {
69+
final term = search.toString().toLowerCase();
70+
71+
final emojis = List.of(gitmojis).where((gitmoji) {
72+
if (term.isEmpty) return true;
73+
return gitmoji.description.toLowerCase().contains(term);
74+
}).toList();
75+
76+
for (int i in _createWindow(selected, lineCount, emojis.length)) {
77+
final gitmoji = emojis[i];
78+
79+
if (i == selected) {
80+
out.write(marker);
81+
} else {
82+
out.write(emptyMarker);
83+
}
84+
85+
out.writeln(' $gitmoji'.padRight(columns - marker.length));
86+
}
87+
88+
out.write('Search: $search');
89+
90+
final byte = stdin.readByteSync();
91+
92+
if (byte == 10) {
93+
out.writeln('\n${emojis[selected]}'.padRight(columns));
94+
break;
95+
}
96+
97+
for (int i = 0; i < min(emojis.length, lineCount); i++) {
98+
out.write('\r\x1b[K\x1b[1A'); // Clear lines.
99+
}
100+
101+
if (byte == 27) {
102+
if (stdin.readByteSync() != 91) continue;
103+
104+
final newByte = stdin.readByteSync();
105+
106+
if (newByte == 66 && selected < emojis.length - 1) selected++;
107+
108+
if (newByte == 65 && selected > 0) selected--;
109+
110+
continue;
111+
}
112+
113+
if (byte == 127) {
114+
final s = search.toString();
115+
if (s.isNotEmpty) {
116+
search.clear();
117+
search.write(s.substring(0, s.length - 1));
118+
}
119+
continue;
120+
}
121+
122+
/// 127 backspace
123+
124+
search.writeCharCode(byte);
125+
}
126+
127+
out.writeln('Exit!'.padRight(columns));
128+
129+
io.exit(0);
130+
}
131+
132+
List<int> _createWindow(int selected, int lineCount, int max) {
133+
if (lineCount >= max) return List.generate(max, (i) => i);
134+
135+
if (max - selected < lineCount) {
136+
return List.generate(lineCount, (i) => max - lineCount + i);
137+
}
138+
139+
return List.generate(lineCount, (i) => selected + i);
140+
}

pubspec.lock

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages:
4+
async:
5+
dependency: transitive
6+
description:
7+
name: async
8+
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
9+
url: "https://pub.dev"
10+
source: hosted
11+
version: "2.13.0"
12+
collection:
13+
dependency: transitive
14+
description:
15+
name: collection
16+
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
17+
url: "https://pub.dev"
18+
source: hosted
19+
version: "1.19.1"
20+
http:
21+
dependency: "direct main"
22+
description:
23+
name: http
24+
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
25+
url: "https://pub.dev"
26+
source: hosted
27+
version: "1.6.0"
28+
http_parser:
29+
dependency: transitive
30+
description:
31+
name: http_parser
32+
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
33+
url: "https://pub.dev"
34+
source: hosted
35+
version: "4.1.2"
36+
lints:
37+
dependency: "direct dev"
38+
description:
39+
name: lints
40+
sha256: a5e2b223cb7c9c8efdc663ef484fdd95bb243bff242ef5b13e26883547fce9a0
41+
url: "https://pub.dev"
42+
source: hosted
43+
version: "6.0.0"
44+
meta:
45+
dependency: transitive
46+
description:
47+
name: meta
48+
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
49+
url: "https://pub.dev"
50+
source: hosted
51+
version: "1.17.0"
52+
path:
53+
dependency: "direct main"
54+
description:
55+
name: path
56+
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
57+
url: "https://pub.dev"
58+
source: hosted
59+
version: "1.9.1"
60+
source_span:
61+
dependency: transitive
62+
description:
63+
name: source_span
64+
sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
65+
url: "https://pub.dev"
66+
source: hosted
67+
version: "1.10.1"
68+
string_scanner:
69+
dependency: transitive
70+
description:
71+
name: string_scanner
72+
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
73+
url: "https://pub.dev"
74+
source: hosted
75+
version: "1.4.1"
76+
term_glyph:
77+
dependency: transitive
78+
description:
79+
name: term_glyph
80+
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
81+
url: "https://pub.dev"
82+
source: hosted
83+
version: "1.2.2"
84+
typed_data:
85+
dependency: transitive
86+
description:
87+
name: typed_data
88+
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
89+
url: "https://pub.dev"
90+
source: hosted
91+
version: "1.4.0"
92+
web:
93+
dependency: transitive
94+
description:
95+
name: web
96+
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
97+
url: "https://pub.dev"
98+
source: hosted
99+
version: "1.1.1"
100+
sdks:
101+
dart: ">=3.9.0 <4.0.0"

pubspec.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: gitmoji
2+
description: gitmoji.
3+
version: 0.0.1
4+
5+
environment:
6+
sdk: ^3.9.0
7+
8+
dependencies:
9+
# https://pub.dev/packages/http
10+
http: 1.6.0
11+
12+
# https://pub.dev/packages/path
13+
path: 1.9.1
14+
15+
dev_dependencies:
16+
# https://pub.dev/packages/lints
17+
lints: ^6.0.0

0 commit comments

Comments
 (0)