First commit

This commit is contained in:
wcjbr
2026-08-15 19:11:54 +08:00
commit 5f51a52ca6
18 changed files with 982 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.10)
project(example LANGUAGES CXX)
# 作为顶层项目单独构建时,带上 ConsoleLib;作为子目录时目标已存在。
if(NOT TARGET ConsoleLib)
set(ConsoleLib_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ConsoleLib)
endif()
add_subdirectory(helloworld)
add_subdirectory(keyinput)
+6
View File
@@ -0,0 +1,6 @@
{
"version": 8,
"include": [
"../CMakePresets.json"
]
}
+6
View File
@@ -0,0 +1,6 @@
@echo off
cd /d "%~dp0"
cmake --preset Clang
if errorlevel 1 exit /b 1
cmake --build --preset Clang -j
if errorlevel 1 exit /b 1
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
cmake --preset Clang
cmake --build --preset Clang -j
+2
View File
@@ -0,0 +1,2 @@
add_executable(helloworld main.cpp)
target_link_libraries(helloworld PRIVATE ConsoleLib)
+14
View File
@@ -0,0 +1,14 @@
#include <ConsoleLib.h>
#include <atomic>
#include <string>
using namespace ConsoleLib;
signed main() {
initConsole();
clearConsole();
printToConsole("HelloWorld!\r\n");
printToConsole("Red", 0xff0000);
printToConsole("Green", 0x00ff00);
printToConsole("Blue", 0x0000ff);
quit(0);
}
+2
View File
@@ -0,0 +1,2 @@
add_executable(keyinput main.cpp)
target_link_libraries(keyinput PRIVATE ConsoleLib)
+63
View File
@@ -0,0 +1,63 @@
#include <ConsoleLib.h>
using namespace ConsoleLib;
signed main() {
initConsole();
clearConsole();
printToConsole("ConsoleLib key input example\r\n");
printToConsole("Press arrow keys, Home/End, F1-F4, or any printable key.\r\n");
printToConsole("Press q or ESC to quit.\r\n");
while (true) {
// getConsoleKeyInput() 返回按键表并清空本次记录。
auto& keys = getConsoleKeyInput();
if (keys[KEY_UP]) {
printToConsole("UP\r\n");
}
if (keys[KEY_DOWN]) {
printToConsole("DOWN\r\n");
}
if (keys[KEY_LEFT]) {
printToConsole("LEFT\r\n");
}
if (keys[KEY_RIGHT]) {
printToConsole("RIGHT\r\n");
}
if (keys[KEY_HOME]) {
printToConsole("HOME\r\n");
}
if (keys[KEY_END]) {
printToConsole("END\r\n");
}
if (keys[KEY_F1]) {
printToConsole("F1\r\n");
}
if (keys[KEY_F2]) {
printToConsole("F2\r\n");
}
if (keys[KEY_F3]) {
printToConsole("F3\r\n");
}
if (keys[KEY_F4]) {
printToConsole("F4\r\n");
}
for (int c = 32; c < static_cast<int>(ASCII_TABLE_SIZE); ++c) {
if (keys[static_cast<Keycode>(c)]) {
char text[2] = {static_cast<char>(c), '\0'};
printToConsole(text);
}
}
if (keys[KEY_q] || keys[KEY_ESCAPE]) {
break;
}
sleep_ms(16);
}
quit(0);
}