mirror of
https://github.com/m1ngsama/TNT.git
synced 2026-02-08 00:54:03 +00:00
This PR addresses critical performance bottlenecks, improves UX, and eliminates technical debt. ### Key Changes **1. Performance Optimization:** - **Startup**: Rewrote `message_load` to scan `messages.log` backwards from the end - Complexity reduced from O(FileSize) to O(MaxMessages) - Large log file startup: seconds → milliseconds - **Rendering**: Optimized TUI rendering to use line clearing (`\033[K`) instead of full-screen clearing (`\033[2J`) - Eliminated visual flicker **2. libssh API Migration:** - Replaced deprecated message-based API with callback-based server implementation - Removed `#pragma GCC diagnostic ignored "-Wdeprecated-declarations"` - Ensures future libssh compatibility **3. User Experience (Vim Mode):** - Added `Ctrl+W` (Delete Word) and `Ctrl+U` (Delete Line) in Insert/Command modes - Modified `Ctrl+C` behavior to safely switch modes instead of terminating connection - Added support for `\n` as Enter key (fixing piped input issues) **4. Project Structure:** - Moved all test scripts to `tests/` directory - Added `make test` target - Updated CI/CD to run comprehensive test suite ### Verification - ✅ All tests passing (17/17) - ✅ CI passing on Ubuntu and macOS - ✅ AddressSanitizer clean - ✅ Valgrind clean (no memory leaks) - ✅ Zero compilation warnings ### Code Quality **Rating:** 🟢 Good Taste - Algorithm-driven optimization (not hacks) - Simplified architecture (callback-based API) - Zero breaking changes (all tests pass)
46 lines
874 B
C
46 lines
874 B
C
#ifndef COMMON_H
|
|
#define COMMON_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <time.h>
|
|
#include <pthread.h>
|
|
|
|
/* Project Metadata */
|
|
#define TNT_VERSION "1.0.0"
|
|
|
|
/* Configuration constants */
|
|
#define DEFAULT_PORT 2222
|
|
#define MAX_MESSAGES 100
|
|
#define MAX_USERNAME_LEN 64
|
|
#define MAX_MESSAGE_LEN 1024
|
|
#define MAX_CLIENTS 64
|
|
#define LOG_FILE "messages.log"
|
|
#define HOST_KEY_FILE "host_key"
|
|
|
|
/* ANSI color codes */
|
|
#define ANSI_RESET "\033[0m"
|
|
#define ANSI_BOLD "\033[1m"
|
|
#define ANSI_REVERSE "\033[7m"
|
|
#define ANSI_CLEAR "\033[2J"
|
|
#define ANSI_HOME "\033[H"
|
|
#define ANSI_CLEAR_LINE "\033[K"
|
|
|
|
/* Operating modes */
|
|
typedef enum {
|
|
MODE_INSERT,
|
|
MODE_NORMAL,
|
|
MODE_COMMAND,
|
|
MODE_HELP
|
|
} client_mode_t;
|
|
|
|
/* Help language */
|
|
typedef enum {
|
|
LANG_EN,
|
|
LANG_ZH
|
|
} help_lang_t;
|
|
|
|
#endif /* COMMON_H */
|