mirror of
https://github.com/marcusDenslow/FERRUM.git
synced 2026-10-25 12:22:24 +01:00
updated folder structure
This commit is contained in:
63
include/aliases.h
Normal file
63
include/aliases.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* aliases.h
|
||||
* Definitions for shell alias functionality
|
||||
*/
|
||||
|
||||
#ifndef ALIASES_H
|
||||
#define ALIASES_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Structure to represent an alias
|
||||
typedef struct AliasEntry {
|
||||
char *name; // Alias name (command to type)
|
||||
char *command; // The command it expands to
|
||||
} AliasEntry;
|
||||
|
||||
// Initialize alias system
|
||||
void init_aliases(void);
|
||||
|
||||
// Clean up alias system
|
||||
void cleanup_aliases(void);
|
||||
|
||||
// Shutdown the alias system
|
||||
void shutdown_aliases(void);
|
||||
|
||||
// Load aliases from file
|
||||
int load_aliases(void);
|
||||
|
||||
// Save aliases to file
|
||||
int save_aliases(void);
|
||||
|
||||
// Add a new alias
|
||||
int add_alias(const char *name, const char *command);
|
||||
|
||||
// Remove an alias
|
||||
int remove_alias(const char *name);
|
||||
|
||||
// Find an alias by name
|
||||
AliasEntry* find_alias(const char *name);
|
||||
|
||||
// Expand a command line by replacing aliases
|
||||
char* expand_aliases(const char *command);
|
||||
|
||||
// Command handler for the "alias" command
|
||||
int lsh_alias(char **args);
|
||||
|
||||
// Command handler for the "unalias" command
|
||||
int lsh_unalias(char **args);
|
||||
|
||||
// Command handler to list all aliases
|
||||
int lsh_aliases(char **args);
|
||||
|
||||
// Get alias names for tab completion
|
||||
char** get_alias_names(int *count);
|
||||
|
||||
// Expand alias in args array
|
||||
char** expand_alias(char **args);
|
||||
|
||||
// Global variables for alias storage
|
||||
extern AliasEntry *aliases;
|
||||
extern int alias_count;
|
||||
|
||||
#endif // ALIASES_H
|
||||
50
include/autocorrect.h
Normal file
50
include/autocorrect.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* autocorrect.h
|
||||
* Header for command auto-correction functionality
|
||||
*/
|
||||
|
||||
#ifndef AUTOCORRECT_H
|
||||
#define AUTOCORRECT_H
|
||||
|
||||
#include "common.h"
|
||||
#include "line_reader.h"
|
||||
#include <limits.h>
|
||||
|
||||
/**
|
||||
* Calculate Levenshtein distance between two strings
|
||||
*
|
||||
* @param s1 First string
|
||||
* @param s2 Second string
|
||||
* @return Edit distance between the strings
|
||||
*/
|
||||
int levenshtein_distance(const char *s1, const char *s2);
|
||||
|
||||
/**
|
||||
* Helper function to find minimum of three integers
|
||||
*/
|
||||
int min3(int a, int b, int c);
|
||||
|
||||
/**
|
||||
* Initialize the autocorrect system
|
||||
*/
|
||||
void init_autocorrect(void);
|
||||
|
||||
/**
|
||||
* Shutdown the autocorrect system
|
||||
*/
|
||||
void shutdown_autocorrect(void);
|
||||
|
||||
/**
|
||||
* Check a command for possible corrections
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return Corrected arguments array (must be freed by caller) or NULL if no correction
|
||||
*/
|
||||
char **check_for_corrections(char **args);
|
||||
|
||||
/**
|
||||
* Count the number of arguments in a NULL-terminated array
|
||||
*/
|
||||
int count_args(char **args);
|
||||
|
||||
#endif // AUTOCORRECT_H
|
||||
57
include/bookmarks.h
Normal file
57
include/bookmarks.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* bookmarks.h
|
||||
* Functions for managing directory bookmarks
|
||||
*/
|
||||
|
||||
#ifndef BOOKMARKS_H
|
||||
#define BOOKMARKS_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Structure to represent a bookmark
|
||||
typedef struct {
|
||||
char *name; // Bookmark name
|
||||
char *path; // Directory path
|
||||
} BookmarkEntry;
|
||||
|
||||
// Initialize bookmark system
|
||||
void init_bookmarks(void);
|
||||
|
||||
// Clean up bookmark system
|
||||
void cleanup_bookmarks(void);
|
||||
|
||||
// Shutdown the bookmark system
|
||||
void shutdown_bookmarks(void);
|
||||
|
||||
// Load bookmarks from file
|
||||
int load_bookmarks(void);
|
||||
|
||||
// Save bookmarks to file
|
||||
int save_bookmarks(void);
|
||||
|
||||
// Add a new bookmark
|
||||
int add_bookmark(const char *name, const char *path);
|
||||
|
||||
// Remove a bookmark by name
|
||||
int remove_bookmark(const char *name);
|
||||
|
||||
// Find a bookmark by name
|
||||
BookmarkEntry *find_bookmark(const char *name);
|
||||
|
||||
// Command handlers
|
||||
int lsh_bookmark(char **args); // Add a bookmark
|
||||
int lsh_bookmarks(char **args); // List all bookmarks
|
||||
int lsh_goto(char **args); // Jump to a bookmark
|
||||
int lsh_unbookmark(char **args); // Remove a bookmark
|
||||
|
||||
// Get bookmarked directories for tab completion
|
||||
char **get_bookmark_names(int *count);
|
||||
|
||||
// Find a matching bookmark by partial name
|
||||
char *find_matching_bookmark(const char *partial_name);
|
||||
|
||||
// Global bookmarks array
|
||||
extern BookmarkEntry *bookmarks;
|
||||
extern int bookmark_count;
|
||||
|
||||
#endif // BOOKMARKS_H
|
||||
102
include/builtins.h
Normal file
102
include/builtins.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* builtins.h
|
||||
* Declarations for all built-in shell commands
|
||||
*/
|
||||
|
||||
#ifndef BUILTINS_H
|
||||
#define BUILTINS_H
|
||||
|
||||
#include "common.h"
|
||||
#include "system_monitor.h"
|
||||
#include <time.h>
|
||||
|
||||
// Syntax highlighting definitions using ANSI colors
|
||||
#define COLOR_DEFAULT ANSI_COLOR_RESET
|
||||
#define COLOR_KEYWORD ANSI_COLOR_CYAN
|
||||
#define COLOR_STRING ANSI_COLOR_GREEN
|
||||
#define COLOR_COMMENT "\x1b[90m" // Dark gray
|
||||
#define COLOR_NUMBER ANSI_COLOR_MAGENTA
|
||||
#define COLOR_PREPROCESSOR ANSI_COLOR_YELLOW
|
||||
#define COLOR_IDENTIFIER "\x1b[97m" // Bright white
|
||||
|
||||
// Add declarations for color functions
|
||||
void set_color(int color);
|
||||
void reset_color();
|
||||
|
||||
// History command implementation
|
||||
#define HISTORY_SIZE 10
|
||||
|
||||
// New struct to hold history entries with timestamps
|
||||
typedef struct {
|
||||
char *command;
|
||||
time_t timestamp;
|
||||
} HistoryEntry;
|
||||
|
||||
// History variables - made extern to be accessible from line_reader.c
|
||||
extern HistoryEntry command_history[HISTORY_SIZE];
|
||||
extern int history_count;
|
||||
extern int history_index;
|
||||
|
||||
// Built-in command declarations
|
||||
int lsh_cd(char **args);
|
||||
int lsh_help(char **args);
|
||||
int lsh_exit(char **args);
|
||||
int lsh_dir(char **args);
|
||||
int lsh_clear(char **args);
|
||||
int lsh_mkdir(char **args);
|
||||
int lsh_rmdir(char **args);
|
||||
int lsh_del(char **args);
|
||||
int lsh_touch(char **args);
|
||||
int lsh_pwd(char **args);
|
||||
int lsh_cat(char **args);
|
||||
int lsh_history(char **args);
|
||||
int lsh_copy(char **args);
|
||||
int lsh_paste(char **args);
|
||||
int lsh_move(char **args);
|
||||
int lsh_ps(char **args);
|
||||
int lsh_news(char **args);
|
||||
// Alias command declarations - added for alias support
|
||||
int lsh_alias(char **args);
|
||||
int lsh_unalias(char **args);
|
||||
int lsh_aliases(char **args); // New command to list all aliases
|
||||
// Bookmark command declarations - added for bookmark support
|
||||
int lsh_bookmark(char **args);
|
||||
int lsh_bookmarks(char **args);
|
||||
int lsh_goto(char **args);
|
||||
int lsh_unbookmark(char **args);
|
||||
int lsh_focus_timer(char **args);
|
||||
int lsh_weather(char **args);
|
||||
// Text search command
|
||||
int lsh_grep(char **args);
|
||||
int lsh_actual_grep(char **args);
|
||||
int lsh_ripgrep(char **args);
|
||||
int lsh_fzf_native(char **args);
|
||||
int lsh_clip(char **args);
|
||||
int lsh_echo(char **args);
|
||||
int lsh_self_destruct();
|
||||
int lsh_theme(char **args);
|
||||
int lsh_loc(char **args);
|
||||
int lsh_git_status(char **args);
|
||||
int lsh_gg(char **args);
|
||||
int lsh_stats(char **args);
|
||||
|
||||
// Add command to history
|
||||
void lsh_add_to_history(const char *command);
|
||||
|
||||
// Get number of builtin commands
|
||||
int lsh_num_builtins(void);
|
||||
|
||||
// Expose the builtin command strings and function pointers
|
||||
extern char *builtin_str[];
|
||||
extern int (*builtin_func[])(char **);
|
||||
|
||||
/**
|
||||
* Extract a string value from a JSON object
|
||||
*
|
||||
* @param json The JSON string to parse
|
||||
* @param key The key to find
|
||||
* @return Allocated string containing the value (caller must free)
|
||||
*/
|
||||
char *extract_json_string(const char *json, const char *key);
|
||||
|
||||
#endif // BUILTINS_H
|
||||
116
include/common.h
Normal file
116
include/common.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* common.h
|
||||
* Common includes, defines and macros used throughout the shell
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
// Standard library includes
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h> // For isprint
|
||||
#include <fcntl.h> // For file control
|
||||
#include <unistd.h> // For POSIX API (replaces direct.h)
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h> // For waitpid
|
||||
#include <sys/stat.h> // For stat (replaces fileapi.h)
|
||||
#include <termios.h> // For terminal control
|
||||
#include <sys/ioctl.h> // For console dimensions
|
||||
#include <signal.h> // For signal handling
|
||||
#include <time.h> // For time functions
|
||||
#include <limits.h> // For PATH_MAX
|
||||
|
||||
// Define PATH_MAX if not defined
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 4096
|
||||
#endif
|
||||
|
||||
// Common defines
|
||||
#define LSH_RL_BUFSIZE 1024
|
||||
#define LSH_TOK_BUFSIZE 64
|
||||
#define LSH_TOK_DELIM " \t\r\n\a"
|
||||
|
||||
// Terminal control and color codes (ANSI sequences)
|
||||
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||
#define ANSI_COLOR_BLACK "\x1b[30m"
|
||||
#define ANSI_COLOR_RED "\x1b[31m"
|
||||
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||
#define ANSI_COLOR_YELLOW "\x1b[33m"
|
||||
#define ANSI_COLOR_BLUE "\x1b[34m"
|
||||
#define ANSI_COLOR_MAGENTA "\x1b[35m"
|
||||
#define ANSI_COLOR_CYAN "\x1b[36m"
|
||||
#define ANSI_COLOR_WHITE "\x1b[37m"
|
||||
|
||||
// Background colors
|
||||
#define ANSI_BG_BLACK "\x1b[40m"
|
||||
#define ANSI_BG_RED "\x1b[41m"
|
||||
#define ANSI_BG_GREEN "\x1b[42m"
|
||||
#define ANSI_BG_YELLOW "\x1b[43m"
|
||||
#define ANSI_BG_BLUE "\x1b[44m"
|
||||
#define ANSI_BG_MAGENTA "\x1b[45m"
|
||||
#define ANSI_BG_CYAN "\x1b[46m"
|
||||
#define ANSI_BG_WHITE "\x1b[47m"
|
||||
|
||||
// Cursor movement and screen control
|
||||
#define ANSI_CLEAR_SCREEN "\x1b[2J"
|
||||
#define ANSI_CURSOR_HOME "\x1b[H"
|
||||
#define ANSI_SAVE_CURSOR "\x1b[s"
|
||||
#define ANSI_RESTORE_CURSOR "\x1b[u"
|
||||
|
||||
// Key code definitions used by the line reader
|
||||
#define KEY_BACKSPACE 127 // Different on Linux
|
||||
#define KEY_TAB 9
|
||||
#define KEY_ENTER 10 // Linux: 10 (LF) or 13 (CR)
|
||||
#define KEY_ESCAPE 27
|
||||
|
||||
// Special keys (Linux terminal uses escape sequences)
|
||||
// These will need handling in the line reader
|
||||
#define KEY_UP 1000
|
||||
#define KEY_DOWN 1001
|
||||
#define KEY_LEFT 1002
|
||||
#define KEY_RIGHT 1003
|
||||
#define KEY_SHIFT_ENTER 1010
|
||||
#define KEY_SHIFT_TAB 1011
|
||||
|
||||
// Typedefs for compatibility
|
||||
typedef unsigned int UINT;
|
||||
typedef unsigned short WORD;
|
||||
typedef int BOOL;
|
||||
typedef int HANDLE;
|
||||
typedef int DWORD;
|
||||
|
||||
// Define Windows constants
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
// Struct to replace COORD
|
||||
typedef struct {
|
||||
short X;
|
||||
short Y;
|
||||
} COORD;
|
||||
|
||||
// Struct to replace SMALL_RECT
|
||||
typedef struct {
|
||||
short Left;
|
||||
short Top;
|
||||
short Right;
|
||||
short Bottom;
|
||||
} SMALL_RECT;
|
||||
|
||||
// Struct to replace CONSOLE_SCREEN_BUFFER_INFO
|
||||
typedef struct {
|
||||
COORD dwSize;
|
||||
COORD dwCursorPosition;
|
||||
WORD wAttributes;
|
||||
SMALL_RECT srWindow;
|
||||
} CONSOLE_SCREEN_BUFFER_INFO;
|
||||
|
||||
// Struct to replace CONSOLE_CURSOR_INFO
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
BOOL bVisible;
|
||||
} CONSOLE_CURSOR_INFO;
|
||||
|
||||
#endif // COMMON_H
|
||||
57
include/countdown_timer.h
Normal file
57
include/countdown_timer.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* countdown_timer.h
|
||||
* Header for focus timer functionality
|
||||
*/
|
||||
|
||||
#ifndef COUNTDOWN_TIMER_H
|
||||
#define COUNTDOWN_TIMER_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Start a new countdown timer
|
||||
*
|
||||
* @param seconds Total duration in seconds
|
||||
* @param name Optional name for the timer session
|
||||
* @return 1 if successful, 0 on failure
|
||||
*/
|
||||
int start_countdown_timer(int seconds, const char *name);
|
||||
|
||||
/**
|
||||
* Stop the current countdown timer
|
||||
*/
|
||||
void stop_countdown_timer();
|
||||
|
||||
/**
|
||||
* Check if a timer is currently active
|
||||
*
|
||||
* @return TRUE if timer is active, FALSE otherwise
|
||||
*/
|
||||
BOOL is_timer_active();
|
||||
|
||||
/**
|
||||
* Get the current timer display text
|
||||
*
|
||||
* @return Pointer to the display text string
|
||||
*/
|
||||
const char *get_timer_display();
|
||||
|
||||
/**
|
||||
* Temporarily hide the timer display (used when running external programs)
|
||||
*/
|
||||
void hide_timer_display(void);
|
||||
|
||||
/**
|
||||
* Restore the timer display after it was hidden
|
||||
*/
|
||||
void show_timer_display(void);
|
||||
|
||||
/**
|
||||
* Command handler for the "timer" command
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return 1 to continue shell, 0 to exit
|
||||
*/
|
||||
int lsh_focus_timer(char **args);
|
||||
|
||||
#endif // COUNTDOWN_TIMER_H
|
||||
106
include/diff_viewer.h
Normal file
106
include/diff_viewer.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* diff_viewer.h
|
||||
* Interactive diff viewer for git changes
|
||||
*/
|
||||
|
||||
#ifndef DIFF_VIEWER_H
|
||||
#define DIFF_VIEWER_H
|
||||
|
||||
#include "common.h"
|
||||
#include <termios.h>
|
||||
|
||||
#define MAX_FILES 100
|
||||
#define MAX_FILENAME_LEN 256
|
||||
#define MAX_DIFF_LINES 1000
|
||||
|
||||
typedef struct {
|
||||
char filename[MAX_FILENAME_LEN];
|
||||
char status; // 'M' = modified, 'A' = added, 'D' = deleted
|
||||
} ChangedFile;
|
||||
|
||||
typedef struct {
|
||||
char line[512];
|
||||
char type; // '+' = addition, '-' = deletion, ' ' = context
|
||||
int line_number_old;
|
||||
int line_number_new;
|
||||
} DiffLine;
|
||||
|
||||
typedef enum {
|
||||
MODE_FILE_LIST,
|
||||
MODE_FILE_CONTENT
|
||||
} ViewMode;
|
||||
|
||||
typedef struct {
|
||||
ChangedFile files[MAX_FILES];
|
||||
int file_count;
|
||||
int selected_file;
|
||||
DiffLine diff_lines[MAX_DIFF_LINES];
|
||||
int diff_line_count;
|
||||
int diff_scroll_offset;
|
||||
int terminal_width;
|
||||
int terminal_height;
|
||||
int file_panel_width;
|
||||
ViewMode current_mode;
|
||||
} DiffViewer;
|
||||
|
||||
/**
|
||||
* Initialize the diff viewer
|
||||
*/
|
||||
int init_diff_viewer(DiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Get list of changed files from git
|
||||
*/
|
||||
int get_changed_files(DiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Check if a file is a new untracked file
|
||||
*/
|
||||
int is_new_file(const char *filename);
|
||||
|
||||
/**
|
||||
* Load content of a new file and show all lines as additions
|
||||
*/
|
||||
int load_new_file_content(DiffViewer *viewer, const char *filename);
|
||||
|
||||
/**
|
||||
* Load diff for a specific file
|
||||
*/
|
||||
int load_file_diff(DiffViewer *viewer, const char *filename);
|
||||
|
||||
/**
|
||||
* Render the diff viewer interface
|
||||
*/
|
||||
void render_diff_viewer(DiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Handle keyboard input for navigation
|
||||
*/
|
||||
int handle_diff_input(DiffViewer *viewer, char key);
|
||||
|
||||
/**
|
||||
* Run the interactive diff viewer
|
||||
*/
|
||||
int run_diff_viewer(void);
|
||||
|
||||
/**
|
||||
* Clean up diff viewer resources
|
||||
*/
|
||||
void cleanup_diff_viewer(DiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Get terminal size
|
||||
*/
|
||||
void get_terminal_size(int *width, int *height);
|
||||
|
||||
/**
|
||||
* Set terminal to raw mode for interactive input
|
||||
*/
|
||||
void set_raw_mode(struct termios *orig_termios);
|
||||
|
||||
/**
|
||||
* Restore terminal to original mode
|
||||
*/
|
||||
void restore_terminal_mode(struct termios *orig_termios);
|
||||
|
||||
#endif // DIFF_VIEWER_H
|
||||
50
include/favorite_cities.h
Normal file
50
include/favorite_cities.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* favorite_cities.h
|
||||
* Functions for managing favorite cities for weather lookups
|
||||
*/
|
||||
|
||||
#ifndef FAVORITE_CITIES_H
|
||||
#define FAVORITE_CITIES_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Structure to represent a favorite city
|
||||
typedef struct {
|
||||
char name[128]; // City name
|
||||
} CityEntry;
|
||||
|
||||
// Initialize favorite cities system
|
||||
void init_favorite_cities(void);
|
||||
|
||||
// Clean up favorite cities system
|
||||
void cleanup_favorite_cities(void);
|
||||
|
||||
// Shutdown favorite cities system (save and cleanup)
|
||||
void shutdown_favorite_cities(void);
|
||||
|
||||
// Load favorite cities from file
|
||||
int load_favorite_cities(void);
|
||||
|
||||
// Save favorite cities to file
|
||||
int save_favorite_cities(void);
|
||||
|
||||
// Add a new favorite city
|
||||
int add_favorite_city(const char *name);
|
||||
|
||||
// Remove a favorite city
|
||||
int remove_favorite_city(const char *name);
|
||||
|
||||
// Find a favorite city by name
|
||||
CityEntry *find_favorite_city(const char *name);
|
||||
|
||||
// Get favorite city names for tab completion
|
||||
char **get_favorite_city_names(int *count);
|
||||
|
||||
// Command handlers
|
||||
int lsh_cities(char **args); // Main cities command handler
|
||||
|
||||
// Global favorite cities array
|
||||
extern CityEntry *favorite_cities;
|
||||
extern int favorite_city_count;
|
||||
|
||||
#endif // FAVORITE_CITIES_H
|
||||
67
include/filters.h
Normal file
67
include/filters.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* filters.h
|
||||
* Declarations for filter commands (where, sort-by, etc.)
|
||||
*/
|
||||
// this is a test
|
||||
|
||||
#ifndef FILTERS_H
|
||||
#define FILTERS_H
|
||||
|
||||
#include "structured_data.h"
|
||||
|
||||
/**
|
||||
* Filter a table based on a condition (e.g., where size > 10kb)
|
||||
*
|
||||
* @param input The input table
|
||||
* @param args Command arguments
|
||||
* @return Filtered table or NULL on error
|
||||
*/
|
||||
TableData *lsh_where(TableData *input, char **args);
|
||||
|
||||
/**
|
||||
* Sort a table based on a column (e.g., sort-by size desc)
|
||||
*
|
||||
* @param input The input table
|
||||
* @param args Command arguments
|
||||
* @return Sorted table or NULL on error
|
||||
*/
|
||||
TableData *lsh_sort_by(TableData *input, char **args);
|
||||
|
||||
/**
|
||||
* Select specific columns from a table
|
||||
*
|
||||
* @param input The input table
|
||||
* @param args Command arguments
|
||||
* @return Table with selected columns or NULL on error
|
||||
*/
|
||||
TableData *lsh_select(TableData *input, char **args);
|
||||
|
||||
/**
|
||||
* Filter rows where a column contains a substring
|
||||
*
|
||||
* @param input The input table
|
||||
* @param args Command arguments
|
||||
* @return Filtered table or NULL on error
|
||||
*/
|
||||
TableData *lsh_contains(TableData *input, char **args);
|
||||
|
||||
/**
|
||||
* Limit the number of rows displayed
|
||||
*
|
||||
* @param input The input table
|
||||
* @param args Command arguments
|
||||
* @return Limited table or NULL on error
|
||||
*/
|
||||
TableData *lsh_limit(TableData *input, char **args);
|
||||
|
||||
/**
|
||||
* Case-insensitive substring search (strcasestr equivalent for Windows)
|
||||
*/
|
||||
char *my_strcasestr(const char *haystack, const char *needle);
|
||||
|
||||
// Export the filter arrays for the shell
|
||||
extern char *filter_str[];
|
||||
extern TableData *(*filter_func[])(TableData *, char **);
|
||||
extern int filter_count;
|
||||
|
||||
#endif // FILTERS_H
|
||||
57
include/fzf_native.h
Normal file
57
include/fzf_native.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* fzf_native.h
|
||||
* Header for native fzf command-line fuzzy finder wrapper
|
||||
*/
|
||||
|
||||
#ifndef FZF_NATIVE_H
|
||||
#define FZF_NATIVE_H
|
||||
|
||||
#include "builtins.h"
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Check if native fzf is installed on the system
|
||||
*
|
||||
* @return 1 if installed, 0 if not
|
||||
*/
|
||||
int is_fzf_installed(void);
|
||||
|
||||
/**
|
||||
* Display instructions for installing fzf
|
||||
*/
|
||||
void show_fzf_install_instructions(void);
|
||||
|
||||
/**
|
||||
* Run fzf with files from the current directory
|
||||
*
|
||||
* @param preview Enable preview window if 1
|
||||
* @param args Additional arguments for fzf
|
||||
* @return Selected filename or NULL if canceled
|
||||
*/
|
||||
char *run_native_fzf_files(int preview, char **args);
|
||||
|
||||
/**
|
||||
* Run fzf with all files and directories from the current directory
|
||||
*
|
||||
* @param recursive Search recursively if 1
|
||||
* @param args Additional arguments for fzf
|
||||
* @return Selected path or NULL if canceled
|
||||
*/
|
||||
char *run_native_fzf_all(int recursive, char **args);
|
||||
|
||||
/**
|
||||
* Run fzf with command history
|
||||
*
|
||||
* @return Selected command or NULL if canceled
|
||||
*/
|
||||
char *run_native_fzf_history(void);
|
||||
|
||||
/**
|
||||
* Command handler for the fzf command
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return 1 to continue shell execution, 0 to exit shell
|
||||
*/
|
||||
int lsh_fzf_native(char **args);
|
||||
|
||||
#endif // FZF_NATIVE_H
|
||||
119
include/git_integration.h
Normal file
119
include/git_integration.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* git_integration.h
|
||||
* Functions for Git repository detection and information
|
||||
*/
|
||||
|
||||
#ifndef GIT_INTEGRATION_H
|
||||
#define GIT_INTEGRATION_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Initialize Git integration
|
||||
*/
|
||||
void init_git_integration(void);
|
||||
|
||||
/**
|
||||
* Check if the current directory is in a Git repository and get branch info
|
||||
*
|
||||
* @param branch_name Buffer to store branch name if found
|
||||
* @param buffer_size Size of the branch_name buffer
|
||||
* @param is_dirty Pointer to store dirty status flag (1 if repo has changes)
|
||||
* @return 1 if in a Git repo, 0 otherwise
|
||||
*/
|
||||
int get_git_branch(char *branch_name, size_t buffer_size, int *is_dirty);
|
||||
|
||||
int get_last_commit(char *title, size_t title_size, char *hash,
|
||||
size_t hash_size);
|
||||
|
||||
int get_recent_commit(char commits[][256], int count);
|
||||
|
||||
int get_repo_url(char *url, size_t url_size);
|
||||
|
||||
/**
|
||||
* Get the name of the Git repository
|
||||
*
|
||||
* @param repo_name Buffer to store repo name if found
|
||||
* @param buffer_size Size of the repo_name buffer
|
||||
* @return 1 if name was retrieved, 0 otherwise
|
||||
*/
|
||||
int get_git_repo_name(char *repo_name, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* Get Git status for the current repository
|
||||
*
|
||||
* @return A string with the Git status or NULL if not in a repo
|
||||
* (caller must free the returned string)
|
||||
*/
|
||||
char *get_git_status(void);
|
||||
|
||||
/**
|
||||
* Check if the current branch has diverged from its remote tracking branch
|
||||
*
|
||||
* @param commits_ahead Pointer to store number of commits ahead of remote
|
||||
* @param commits_behind Pointer to store number of commits behind remote
|
||||
* @return 1 if diverged (both ahead and behind > 0), 0 otherwise
|
||||
*/
|
||||
int check_branch_divergence(int *commits_ahead, int *commits_behind);
|
||||
|
||||
int create_git_stash(void);
|
||||
|
||||
int create_git_stash_with_name(const char *stash_name);
|
||||
|
||||
int get_git_stashes(char stashed[][512], int max_stashes);
|
||||
|
||||
/**
|
||||
* Apply a git stash by index (keeps stash in list)
|
||||
*
|
||||
* @param stash_index Index of stash to apply (0 = most recent)
|
||||
* @return 1 if stash was applied successfully, 0 otherwise
|
||||
*/
|
||||
int apply_git_stash(int stash_index);
|
||||
|
||||
/**
|
||||
* Pop a git stash by index (applies and removes stash from list)
|
||||
*
|
||||
* @param stash_index Index of stash to pop (0 = most recent)
|
||||
* @return 1 if stash was popped successfully, 0 otherwise
|
||||
*/
|
||||
int pop_git_stash(int stash_index);
|
||||
|
||||
/**
|
||||
* Drop a git stash by index (removes stash without applying)
|
||||
*
|
||||
* @param stash_index Index of stash to drop (0 = most recent)
|
||||
* @return 1 if stash was dropped successfully, 0 otherwise
|
||||
*/
|
||||
int drop_git_stash(int stash_index);
|
||||
|
||||
/**
|
||||
* Get detailed commit information including diff
|
||||
*
|
||||
* @param commit_hash The commit hash to get info for
|
||||
* @param commit_info Buffer to store formatted commit info
|
||||
* @param info_size Size of commit_info buffer
|
||||
* @return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int get_commit_details(const char *commit_hash, char *commit_info, size_t info_size);
|
||||
|
||||
/**
|
||||
* Get stash diff information
|
||||
*
|
||||
* @param stash_index Index of stash to get diff for
|
||||
* @param stash_diff Buffer to store formatted stash diff
|
||||
* @param diff_size Size of stash_diff buffer
|
||||
* @return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int get_stash_diff(int stash_index, char *stash_diff, size_t diff_size);
|
||||
|
||||
/**
|
||||
* Get commit history for a specific branch
|
||||
*
|
||||
* @param branch_name The branch name to get commits for
|
||||
* @param commits Array to store commit information
|
||||
* @param max_commits Maximum number of commits to retrieve
|
||||
* @return Number of commits retrieved
|
||||
*/
|
||||
int get_branch_commits(const char *branch_name, char commits[][2048], int max_commits);
|
||||
|
||||
#endif // GIT_INTEGRATION_H
|
||||
39
include/grep.h
Normal file
39
include/grep.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* grep.h
|
||||
* Header for fast text searching in files with fuzzy matching capabilities
|
||||
*/
|
||||
|
||||
#ifndef GREP_H
|
||||
#define GREP_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Run grep with interactive interface
|
||||
*
|
||||
* Shows a split view with files on left, matches on right, and
|
||||
* updates search results with each keystroke
|
||||
*/
|
||||
void run_interactive_grep_session(void);
|
||||
|
||||
/**
|
||||
* Command handler for the "grep" command
|
||||
*
|
||||
* Usage: grep [options] pattern [file/directory]
|
||||
* Options:
|
||||
* -n, --line-numbers Show line numbers
|
||||
* -i, --ignore-case Ignore case distinctions
|
||||
* -r, --recursive Search directories recursively
|
||||
* -f, --fuzzy Use fuzzy matching instead of exact
|
||||
* --file Specify files/directories to search (otherwise searches
|
||||
* current dir)
|
||||
*
|
||||
* If called without arguments, opens an interactive grep UI with a split view
|
||||
* that updates as you type.
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return 1 to continue shell execution, 0 to exit shell
|
||||
*/
|
||||
int lsh_grep(char **args);
|
||||
|
||||
#endif // GREP_H
|
||||
59
include/line_reader.h
Normal file
59
include/line_reader.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* line_reader.h
|
||||
* Functions for reading and parsing command lines
|
||||
*/
|
||||
|
||||
#ifndef LINE_READER_H
|
||||
#define LINE_READER_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Check if a command is valid
|
||||
*
|
||||
* @param cmd The command to check
|
||||
* @return 1 if valid, 0 if not
|
||||
*/
|
||||
int is_valid_command(const char *cmd);
|
||||
|
||||
/**
|
||||
* Read a key from the terminal
|
||||
*
|
||||
* Handles special keys and escape sequences
|
||||
*/
|
||||
int read_key(void);
|
||||
|
||||
/**
|
||||
* Read a line of input from the user with tab completion
|
||||
*
|
||||
* @return The line read from stdin (must be freed by caller)
|
||||
*/
|
||||
char *lsh_read_line(void);
|
||||
|
||||
void generate_enhanced_prompt(char *prompt_buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* Split a line into tokens
|
||||
*
|
||||
* @param line The line to split
|
||||
* @return An array of tokens (must be freed by caller)
|
||||
*/
|
||||
char **lsh_split_line(char *line);
|
||||
|
||||
/**
|
||||
* Parse a token from a string, handling quoted strings
|
||||
*
|
||||
* @param str_ptr Pointer to the string to parse, will be updated
|
||||
* @return The parsed token, or NULL if no more tokens
|
||||
*/
|
||||
char *parse_token(char **str_ptr);
|
||||
|
||||
/**
|
||||
* Split a line with pipes into separate command arrays
|
||||
*
|
||||
* @param line The line to split
|
||||
* @return NULL-terminated array of NULL-terminated token arrays
|
||||
*/
|
||||
char ***lsh_split_piped_line(char *line);
|
||||
|
||||
#endif // LINE_READER_H
|
||||
571
include/ncurses_diff_viewer.h
Normal file
571
include/ncurses_diff_viewer.h
Normal file
@@ -0,0 +1,571 @@
|
||||
/**
|
||||
* ncurses_diff_viewer.h
|
||||
* NCurses-based interactive diff viewer for git changes
|
||||
*/
|
||||
|
||||
#ifndef NCURSES_DIFF_VIEWER_H
|
||||
#define NCURSES_DIFF_VIEWER_H
|
||||
|
||||
#include "common.h"
|
||||
#include <ncurses.h>
|
||||
|
||||
#define MAX_FILES 100
|
||||
#define MAX_FILENAME_LEN 256
|
||||
#define MAX_FULL_FILE_LINES 2000
|
||||
#define MAX_COMMITS 50
|
||||
#define MAX_COMMIT_TITLE_LEN 256
|
||||
#define MAX_AUTHOR_INITIALS 3
|
||||
#define MAX_STASHES 100
|
||||
#define MAX_BRANCHES 5
|
||||
#define MAX_BRANCHNAME_LEN 256
|
||||
|
||||
typedef struct {
|
||||
char stash_info[512];
|
||||
} NCursesStash;
|
||||
|
||||
typedef struct {
|
||||
char filename[MAX_FILENAME_LEN];
|
||||
char status; // 'M' = modified, 'A' = added, 'D' = deleted
|
||||
int marked_for_commit; // 1 if marked for commit, 0 otherwise
|
||||
int has_staged_changes;
|
||||
} NCursesChangedFile;
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_BRANCHNAME_LEN];
|
||||
int status;
|
||||
int commits_ahead;
|
||||
int commits_behind;
|
||||
} NCursesBranches;
|
||||
|
||||
typedef struct {
|
||||
char line[1024];
|
||||
char type; // '+' = addition, '-' = deletion, ' ' = context, '@' = hunk header
|
||||
int is_diff_line; // 1 if this is a diff line, 0 if original file line
|
||||
int hunk_id;
|
||||
int is_staged;
|
||||
int line_number_old;
|
||||
int line_number_new;
|
||||
int is_context;
|
||||
} NCursesFileLine;
|
||||
|
||||
typedef struct {
|
||||
char hash[16]; // Short commit hash
|
||||
char author_initials[MAX_AUTHOR_INITIALS];
|
||||
char title[MAX_COMMIT_TITLE_LEN];
|
||||
int is_pushed; // 1 if pushed to remote, 0 if local only
|
||||
} NCursesCommit;
|
||||
|
||||
typedef enum {
|
||||
NCURSES_MODE_FILE_LIST,
|
||||
NCURSES_MODE_FILE_VIEW,
|
||||
NCURSES_MODE_COMMIT_LIST,
|
||||
NCURSES_MODE_COMMIT_VIEW,
|
||||
NCURSES_MODE_STASH_LIST,
|
||||
NCURSES_MODE_STASH_VIEW,
|
||||
NCURSES_MODE_BRANCH_LIST,
|
||||
NCURSES_MODE_BRANCH_VIEW
|
||||
} NCursesViewMode;
|
||||
|
||||
typedef enum {
|
||||
SYNC_STATUS_IDLE,
|
||||
SYNC_STATUS_SYNCING_APPEARING,
|
||||
SYNC_STATUS_SYNCING_VISIBLE,
|
||||
SYNC_STATUS_SYNCING_DISAPPEARING,
|
||||
SYNC_STATUS_PUSHING_APPEARING,
|
||||
SYNC_STATUS_PUSHING_VISIBLE,
|
||||
SYNC_STATUS_PUSHING_DISAPPEARING,
|
||||
SYNC_STATUS_PULLING_APPEARING,
|
||||
SYNC_STATUS_PULLING_VISIBLE,
|
||||
SYNC_STATUS_PULLING_DISAPPEARING,
|
||||
SYNC_STATUS_SYNCED_APPEARING,
|
||||
SYNC_STATUS_SYNCED_VISIBLE,
|
||||
SYNC_STATUS_SYNCED_DISAPPEARING,
|
||||
SYNC_STATUS_PUSHED_APPEARING,
|
||||
SYNC_STATUS_PUSHED_VISIBLE,
|
||||
SYNC_STATUS_PUSHED_DISAPPEARING,
|
||||
SYNC_STATUS_PULLED_APPEARING,
|
||||
SYNC_STATUS_PULLED_VISIBLE,
|
||||
SYNC_STATUS_PULLED_DISAPPEARING
|
||||
} SyncStatus;
|
||||
|
||||
typedef struct {
|
||||
NCursesChangedFile files[MAX_FILES];
|
||||
int file_count;
|
||||
int selected_file;
|
||||
NCursesFileLine file_lines[MAX_FULL_FILE_LINES];
|
||||
int file_line_count;
|
||||
int file_scroll_offset;
|
||||
int file_cursor_line;
|
||||
NCursesCommit commits[MAX_COMMITS];
|
||||
int commit_count;
|
||||
int selected_commit;
|
||||
int commit_scroll_offset;
|
||||
NCursesStash stashes[MAX_STASHES];
|
||||
NCursesBranches branches[MAX_BRANCHES];
|
||||
int stash_count;
|
||||
int branch_count;
|
||||
int selected_stash;
|
||||
int stash_scroll_offset;
|
||||
int selected_branch;
|
||||
WINDOW *file_list_win;
|
||||
WINDOW *file_content_win;
|
||||
WINDOW *commit_list_win;
|
||||
WINDOW *stash_list_win;
|
||||
WINDOW *branch_list_win;
|
||||
WINDOW *status_bar_win;
|
||||
int terminal_width;
|
||||
int terminal_height;
|
||||
int file_panel_width;
|
||||
int file_panel_height;
|
||||
int commit_panel_height;
|
||||
int stash_panel_height;
|
||||
int branch_panel_height;
|
||||
int status_bar_height;
|
||||
NCursesViewMode current_mode;
|
||||
SyncStatus sync_status;
|
||||
int spinner_frame;
|
||||
time_t last_sync_time;
|
||||
int animation_frame;
|
||||
int text_char_count;
|
||||
int pushing_branch_index;
|
||||
int pulling_branch_index;
|
||||
SyncStatus branch_push_status;
|
||||
SyncStatus branch_pull_status;
|
||||
int branch_animation_frame;
|
||||
int branch_text_char_count;
|
||||
int critical_operation_in_progress; // Prevent fetching during critical ops
|
||||
|
||||
// Background fetch management
|
||||
pid_t fetch_pid; // Process ID of background fetch
|
||||
int fetch_in_progress; // Flag to track if fetch is running
|
||||
|
||||
// Branch-specific commits for hover functionality
|
||||
char branch_commits[MAX_COMMITS][2048]; // Larger buffer for formatted commits
|
||||
int branch_commit_count;
|
||||
char current_branch_for_commits[MAX_BRANCHNAME_LEN];
|
||||
int branch_commits_scroll_offset;
|
||||
int branch_commits_cursor_line;
|
||||
|
||||
int split_view_mode; // 0 = normal view, 1 = split staged/unstaged
|
||||
int staged_scroll_offset; // Scroll position for staged pane
|
||||
int active_pane; // 0 = unstaged, 1 = staged
|
||||
char current_file_path[512]; // Path of currently viewed file
|
||||
int total_hunks; // Total number of hunks in current file
|
||||
NCursesFileLine
|
||||
staged_lines[MAX_FULL_FILE_LINES]; // Separate storage for staged content
|
||||
int staged_line_count; // Number of lines in staged view
|
||||
int staged_cursor_line;
|
||||
|
||||
// Fuzzy search state
|
||||
int fuzzy_search_active; // 1 if fuzzy search is active
|
||||
char fuzzy_search_query[256]; // Current search query
|
||||
int fuzzy_search_query_len; // Length of current query
|
||||
|
||||
// Scored search results
|
||||
struct {
|
||||
int file_index;
|
||||
int score;
|
||||
} fuzzy_scored_files[MAX_FILES]; // Scored and sorted results
|
||||
|
||||
int fuzzy_filtered_count; // Number of filtered files
|
||||
int fuzzy_selected_index; // Currently selected in fuzzy list
|
||||
int fuzzy_scroll_offset; // Scroll position in fuzzy list
|
||||
WINDOW *fuzzy_input_win; // Input window for search
|
||||
WINDOW *fuzzy_list_win; // Results list window
|
||||
|
||||
// State tracking to prevent unnecessary redraws
|
||||
int fuzzy_needs_full_redraw; // 1 if full redraw needed (borders, input, list)
|
||||
int fuzzy_needs_input_redraw; // 1 if input field needs redraw
|
||||
int fuzzy_needs_list_redraw; // 1 if file list needs redraw
|
||||
char fuzzy_last_query[256]; // Last rendered query
|
||||
int fuzzy_last_selected; // Last rendered selection
|
||||
int fuzzy_last_scroll; // Last rendered scroll position
|
||||
int fuzzy_last_filtered_count; // Last rendered result count
|
||||
|
||||
// Generic grep search state (for commits, stashes, branches)
|
||||
int grep_search_active; // 1 if grep search is active
|
||||
NCursesViewMode grep_search_mode; // Which mode grep is searching in
|
||||
char grep_search_query[256]; // Current search query
|
||||
int grep_search_query_len; // Length of current query
|
||||
|
||||
// Scored grep search results
|
||||
struct {
|
||||
int item_index;
|
||||
int score;
|
||||
} grep_scored_items[MAX_COMMITS]; // Scored and sorted results (reuse
|
||||
// MAX_COMMITS)
|
||||
|
||||
int grep_filtered_count; // Number of filtered items
|
||||
int grep_selected_index; // Currently selected in grep list
|
||||
int grep_scroll_offset; // Scroll position in grep list
|
||||
WINDOW *grep_input_win; // Input window for search
|
||||
WINDOW *grep_list_win; // Results list window
|
||||
|
||||
// State tracking for grep search rendering
|
||||
int grep_needs_full_redraw; // 1 if full redraw needed
|
||||
int grep_needs_input_redraw; // 1 if input field needs redraw
|
||||
int grep_needs_list_redraw; // 1 if item list needs redraw
|
||||
char grep_last_query[256]; // Last rendered query
|
||||
int grep_last_selected; // Last rendered selection
|
||||
int grep_last_scroll; // Last rendered scroll position
|
||||
int grep_last_filtered_count; // Last rendered result count
|
||||
|
||||
} NCursesDiffViewer;
|
||||
|
||||
/**
|
||||
* Initialize the ncurses diff viewer
|
||||
*/
|
||||
int init_ncurses_diff_viewer(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Get list of changed files from git
|
||||
*/
|
||||
int get_ncurses_changed_files(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Load full file content with diff highlighting
|
||||
*/
|
||||
int load_full_file_with_diff(NCursesDiffViewer *viewer, const char *filename);
|
||||
|
||||
/**
|
||||
* Render the file list window
|
||||
*/
|
||||
void render_file_list_window(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Render the file content window
|
||||
*/
|
||||
void render_file_content_window(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Handle keyboard input for navigation
|
||||
*/
|
||||
int handle_ncurses_diff_input(NCursesDiffViewer *viewer, int key);
|
||||
|
||||
/**
|
||||
* Run the ncurses diff viewer
|
||||
*/
|
||||
int run_ncurses_diff_viewer(void);
|
||||
|
||||
/**
|
||||
* Clean up ncurses diff viewer resources
|
||||
*/
|
||||
void cleanup_ncurses_diff_viewer(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Create temporary file with current working version
|
||||
*/
|
||||
int create_temp_file_with_changes(const char *filename, char *temp_path);
|
||||
|
||||
/**
|
||||
* Create temporary file with git HEAD version
|
||||
*/
|
||||
int create_temp_file_git_version(const char *filename, char *temp_path);
|
||||
|
||||
/**
|
||||
* Get commit history
|
||||
*/
|
||||
int get_commit_history(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Toggle file marking for commit
|
||||
*/
|
||||
void toggle_file_mark(NCursesDiffViewer *viewer, int file_index);
|
||||
|
||||
/**
|
||||
* Mark all files for commit
|
||||
*/
|
||||
void mark_all_files(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Commit marked files with title and message
|
||||
*/
|
||||
int commit_marked_files(NCursesDiffViewer *viewer, const char *commit_title,
|
||||
const char *commit_message);
|
||||
|
||||
/**
|
||||
* Push specific commit
|
||||
*/
|
||||
int push_commit(NCursesDiffViewer *viewer, int commit_index);
|
||||
|
||||
/**
|
||||
* Pull commits from remote
|
||||
*/
|
||||
int pull_commits(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Render the commit list window
|
||||
*/
|
||||
void render_commit_list_window(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Get commit title and message input from user
|
||||
*/
|
||||
int get_commit_title_input(char *title, int max_len, char *message,
|
||||
int max_message_len);
|
||||
|
||||
/**
|
||||
* Draw a box with rounded corners
|
||||
*/
|
||||
void draw_rounded_box(WINDOW *win);
|
||||
|
||||
/**
|
||||
* Render the status bar
|
||||
*/
|
||||
void render_status_bar(NCursesDiffViewer *viewer);
|
||||
|
||||
void render_branch_list_window(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Update sync status and check for new files
|
||||
*/
|
||||
void update_sync_status(NCursesDiffViewer *viewer);
|
||||
|
||||
int get_ncurses_git_stashes(NCursesDiffViewer *viewer);
|
||||
|
||||
int get_ncurses_git_branches(NCursesDiffViewer *viewer);
|
||||
|
||||
typedef enum {
|
||||
DELETE_LOCAL = 0,
|
||||
DELETE_REMOTE = 1,
|
||||
DELETE_BOTH = 2,
|
||||
DELETE_CANCEL = 3
|
||||
} DeleteBranchOption;
|
||||
|
||||
int get_branch_name_input(char *branch_name, int max_len);
|
||||
|
||||
int create_git_branch(const char *branch_name);
|
||||
|
||||
int get_rename_branch_input(const char *current_name, char *new_name,
|
||||
int max_len);
|
||||
|
||||
int rename_git_branch(const char *old_name, const char *new_name);
|
||||
|
||||
int show_delete_branch_dialog(const char *branch_name);
|
||||
|
||||
void show_error_popup(const char *error_message);
|
||||
|
||||
int get_git_remotes(char remotes[][256], int max_remotes);
|
||||
|
||||
int show_upstream_selection_dialog(const char *branch_name,
|
||||
char *upstream_result, int max_len);
|
||||
|
||||
int get_current_branch_name(char *branch_name, int max_len);
|
||||
|
||||
int branch_has_upstream(const char *branch_name);
|
||||
|
||||
int delete_git_branch(const char *branch_name, DeleteBranchOption option);
|
||||
|
||||
int create_ncurses_git_stash(NCursesDiffViewer *viewer);
|
||||
|
||||
int get_stash_name_input(char *stash_name, int max_len);
|
||||
|
||||
void render_stash_list_window(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Load commit details for viewing
|
||||
*/
|
||||
int load_commit_for_viewing(NCursesDiffViewer *viewer, const char *commit_hash);
|
||||
|
||||
/**
|
||||
* Load stash details for viewing
|
||||
*/
|
||||
int load_stash_for_viewing(NCursesDiffViewer *viewer, int stash_index);
|
||||
|
||||
/**
|
||||
* Load commits for a specific branch for the hover preview
|
||||
*/
|
||||
int load_branch_commits(NCursesDiffViewer *viewer, const char *branch_name);
|
||||
|
||||
/**
|
||||
* Parse branch commits into navigable lines for branch view mode
|
||||
*/
|
||||
int parse_branch_commits_to_lines(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Start background fetch process
|
||||
*/
|
||||
void start_background_fetch(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Check if background fetch is complete and update UI accordingly
|
||||
*/
|
||||
void check_background_fetch(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Move cursor up/down while skipping empty lines
|
||||
*/
|
||||
void move_cursor_smart(NCursesDiffViewer *viewer, int direction);
|
||||
|
||||
/**
|
||||
* Move cursor up/down in unstaged pane with proper scrolling
|
||||
*/
|
||||
void move_cursor_smart_unstaged(NCursesDiffViewer *viewer, int direction);
|
||||
|
||||
/**
|
||||
* Move cursor up/down in staged pane with proper scrolling
|
||||
*/
|
||||
void move_cursor_smart_staged(NCursesDiffViewer *viewer, int direction);
|
||||
|
||||
/**
|
||||
* Helper function to wrap a long line into multiple display lines
|
||||
*/
|
||||
int wrap_line_to_width(const char *input_line, char wrapped_lines[][1024],
|
||||
int max_lines, int width);
|
||||
|
||||
/**
|
||||
* Render a single line with proper wrapping and coloring
|
||||
*/
|
||||
int render_wrapped_line(WINDOW *win, const char *line, int start_y, int start_x,
|
||||
int width, int max_rows, int color_pair, int reverse);
|
||||
|
||||
/**
|
||||
* Calculate how many display lines a wrapped line will take
|
||||
*/
|
||||
int calculate_wrapped_line_height(const char *line, int width);
|
||||
|
||||
/**
|
||||
* Load file preview showing the top of the file content
|
||||
*/
|
||||
int load_file_preview(NCursesDiffViewer *viewer, const char *filename);
|
||||
|
||||
/**
|
||||
* Update preview based on current mode and selection
|
||||
*/
|
||||
void update_preview_for_current_selection(NCursesDiffViewer *viewer);
|
||||
|
||||
int get_single_input(const char *title, const char *prompt, char *input,
|
||||
int input_len, int is_password);
|
||||
|
||||
int get_github_credentials(char *username, int username_len, char *token,
|
||||
int token_len);
|
||||
|
||||
int execute_git_with_auth(const char *base_cmd, const char *username,
|
||||
const char *token);
|
||||
|
||||
int stage_hunk_by_line(NCursesDiffViewer *viewer, int line_index);
|
||||
|
||||
int load_file_with_staging_info(NCursesDiffViewer *viewer,
|
||||
const char *filename);
|
||||
|
||||
void rebuild_staged_view(NCursesDiffViewer *viewer);
|
||||
|
||||
int apply_staged_changes(NCursesDiffViewer *viewer);
|
||||
|
||||
int reset_staged_changes(NCursesDiffViewer *viewer);
|
||||
|
||||
int unstage_line_from_git(NCursesDiffViewer *viewer, int staged_line_index);
|
||||
|
||||
int commit_staged_changes_only(NCursesDiffViewer *viewer,
|
||||
const char *commit_title,
|
||||
const char *commit_message);
|
||||
|
||||
void rebuild_staged_view_from_git(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Initialize fuzzy search state
|
||||
*/
|
||||
void init_fuzzy_search(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Cleanup fuzzy search windows
|
||||
*/
|
||||
void cleanup_fuzzy_search(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Enter fuzzy search mode
|
||||
*/
|
||||
void enter_fuzzy_search_mode(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Exit fuzzy search mode
|
||||
*/
|
||||
void exit_fuzzy_search_mode(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Update fuzzy search filter based on current query
|
||||
*/
|
||||
void update_fuzzy_filter(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Render fuzzy search UI
|
||||
*/
|
||||
void render_fuzzy_search(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Render fuzzy search input field only
|
||||
*/
|
||||
void render_fuzzy_input(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Render fuzzy search file list content only
|
||||
*/
|
||||
void render_fuzzy_list_content(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Create fuzzy search windows with borders (one-time setup)
|
||||
*/
|
||||
void create_fuzzy_windows_with_borders(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Handle fuzzy search input
|
||||
*/
|
||||
int handle_fuzzy_search_input(NCursesDiffViewer *viewer, int key);
|
||||
|
||||
/**
|
||||
* Select file from fuzzy search results
|
||||
*/
|
||||
void select_fuzzy_file(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Initialize grep search state
|
||||
*/
|
||||
void init_grep_search(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Cleanup grep search windows
|
||||
*/
|
||||
void cleanup_grep_search(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Enter grep search mode for current view mode
|
||||
*/
|
||||
void enter_grep_search_mode(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Exit grep search mode
|
||||
*/
|
||||
void exit_grep_search_mode(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Update grep search filter based on current query and mode
|
||||
*/
|
||||
void update_grep_filter(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Render grep search UI
|
||||
*/
|
||||
void render_grep_search(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Handle grep search input
|
||||
*/
|
||||
int handle_grep_search_input(NCursesDiffViewer *viewer, int key);
|
||||
|
||||
/**
|
||||
* Select item from grep search results
|
||||
*/
|
||||
void select_grep_item(NCursesDiffViewer *viewer);
|
||||
|
||||
/**
|
||||
* Calculate grep match score for text content
|
||||
*/
|
||||
int calculate_grep_score(const char *pattern, const char *text);
|
||||
|
||||
/**
|
||||
* Extract branch name from stash info
|
||||
*/
|
||||
void extract_branch_from_stash(const char *stash_info, char *branch_name,
|
||||
int max_len);
|
||||
|
||||
#endif // NCURSES_DIFF_VIEWER_H
|
||||
91
include/persistent_history.h
Normal file
91
include/persistent_history.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* persistent_history.h
|
||||
* Functions for persistent command history and frequency tracking
|
||||
*/
|
||||
|
||||
#ifndef PERSISTENT_HISTORY_H
|
||||
#define PERSISTENT_HISTORY_H
|
||||
|
||||
#include "common.h"
|
||||
#include "shell.h"
|
||||
#include <time.h>
|
||||
|
||||
// Increase history size for persistent storage
|
||||
#define PERSISTENT_HISTORY_SIZE 1000
|
||||
|
||||
// Structure for a history entry
|
||||
typedef struct {
|
||||
char *command;
|
||||
time_t timestamp;
|
||||
} PersistentHistoryEntry;
|
||||
|
||||
// Structure for command frequency tracking
|
||||
typedef struct {
|
||||
char *command;
|
||||
int count;
|
||||
} CommandFrequency;
|
||||
|
||||
// Initialize persistent history
|
||||
void init_persistent_history(void);
|
||||
|
||||
// Clean up persistent history
|
||||
void cleanup_persistent_history(void);
|
||||
|
||||
// Shutdown persistent history
|
||||
void shutdown_persistent_history(void);
|
||||
|
||||
// Add a command to persistent history
|
||||
void add_to_history(const char *command);
|
||||
|
||||
// Get command suggestions based on prefix and frequency
|
||||
char **get_frequency_suggestions(const char *prefix, int *num_suggestions);
|
||||
|
||||
// Save history to file
|
||||
void save_history_to_file(void);
|
||||
|
||||
// Load history from file
|
||||
void load_history_from_file(void);
|
||||
|
||||
// Update command frequency
|
||||
void update_command_frequency(const char *command);
|
||||
|
||||
// Save frequencies to file
|
||||
void save_frequencies_to_file(void);
|
||||
|
||||
// Load frequencies from file
|
||||
void load_frequencies_from_file(void);
|
||||
|
||||
// Get the history entry at specified index
|
||||
PersistentHistoryEntry *get_history_entry(int index);
|
||||
|
||||
// Get the total number of history entries
|
||||
int get_history_count(void);
|
||||
|
||||
// Find the best matching command based on frequency
|
||||
char *find_best_frequency_match(const char *prefix);
|
||||
|
||||
// Debug print frequency data
|
||||
void debug_print_frequencies(void);
|
||||
|
||||
// String search (case insensitive)
|
||||
char *_stristr(const char *haystack, const char *needle);
|
||||
|
||||
// Get previous history entry
|
||||
char *get_previous_history_entry(int *position);
|
||||
|
||||
// Get next history entry
|
||||
char *get_next_history_entry(int *position);
|
||||
|
||||
// Get matching history entries
|
||||
char **get_matching_history_entries(const char *prefix);
|
||||
|
||||
// Free matching entries
|
||||
void free_matching_entries(char **entries);
|
||||
|
||||
// Expose global variables for stats command
|
||||
extern CommandFrequency *command_frequencies;
|
||||
extern int frequency_count;
|
||||
extern PersistentHistoryEntry *history_entries;
|
||||
extern int history_size;
|
||||
|
||||
#endif // PERSISTENT_HISTORY_H
|
||||
26
include/ripgrep.h
Normal file
26
include/ripgrep.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef RIPGREP_H
|
||||
#define RIPGREP_H
|
||||
|
||||
#include "builtins.h"
|
||||
#include "common.h"
|
||||
#include "fzf_native.h"
|
||||
|
||||
int is_rg_installed(void);
|
||||
|
||||
void show_rg_install_instructions(void);
|
||||
|
||||
void show_fzf_install_instructions(void);
|
||||
|
||||
char *run_interactive_ripgrep(char **args);
|
||||
|
||||
int lsh_grep(char **args);
|
||||
|
||||
int lsh_ripgrep(char **args);
|
||||
|
||||
void run_ripgrep_interactive_session(void);
|
||||
|
||||
int rg_open_in_editor(const char *file_path, int line_number);
|
||||
|
||||
int is_editor_available_for_rg(const char *editor);
|
||||
|
||||
#endif // RIPGREP_H
|
||||
141
include/shell.h
Normal file
141
include/shell.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* shell.h
|
||||
* Core shell functionality
|
||||
*/
|
||||
|
||||
#ifndef SHELL_H
|
||||
#define SHELL_H
|
||||
|
||||
#include "common.h"
|
||||
#include "structured_data.h"
|
||||
|
||||
/**
|
||||
* Display a welcome banner with BBQ sauce invention time
|
||||
*/
|
||||
void display_welcome_banner(void);
|
||||
|
||||
/**
|
||||
* Execute a command
|
||||
*
|
||||
* @param args Null-terminated array of command arguments
|
||||
* @return 1 to continue the shell, 0 to exit
|
||||
*/
|
||||
int lsh_execute(char **args);
|
||||
|
||||
/**
|
||||
* Execute a pipeline of commands
|
||||
*
|
||||
* @param commands Null-terminated array of command arrays
|
||||
* @return 1 to continue the shell, 0 to exit
|
||||
*/
|
||||
int lsh_execute_piped(char ***commands);
|
||||
|
||||
/**
|
||||
* Create a TableData structure from an ls command
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return TableData pointer (must be freed by caller) or NULL on error
|
||||
*/
|
||||
TableData* create_ls_table(char **args);
|
||||
|
||||
/**
|
||||
* Parse input line into an array of commands (for pipelines)
|
||||
*
|
||||
* @param line Input command line
|
||||
* @return Null-terminated array of command arrays
|
||||
*/
|
||||
char*** lsh_split_commands(char *line);
|
||||
|
||||
/**
|
||||
* Launch an external program
|
||||
*
|
||||
* @param args Null-terminated array of command arguments
|
||||
* @return Always returns 1 (continue the shell)
|
||||
*/
|
||||
int lsh_launch(char **args);
|
||||
|
||||
/**
|
||||
* Main shell loop
|
||||
*/
|
||||
void lsh_loop(void);
|
||||
|
||||
/**
|
||||
* Free memory for a command array from lsh_split_commands
|
||||
*/
|
||||
void free_commands(char ***commands);
|
||||
|
||||
/**
|
||||
* Initialize the status bar at the bottom of the screen
|
||||
*
|
||||
* @param fd File descriptor for terminal (STDOUT_FILENO)
|
||||
* @return 1 if successful, 0 on failure
|
||||
*/
|
||||
int init_status_bar(int fd);
|
||||
|
||||
/**
|
||||
* Temporarily hide the status bar before command execution
|
||||
*
|
||||
* @param fd File descriptor for terminal (STDOUT_FILENO)
|
||||
*/
|
||||
void hide_status_bar(int fd);
|
||||
|
||||
/**
|
||||
* Ensures there's space for the status bar by scrolling if needed
|
||||
*
|
||||
* @param fd File descriptor for terminal (STDOUT_FILENO)
|
||||
*/
|
||||
void ensure_status_bar_space(int fd);
|
||||
|
||||
/**
|
||||
* Check for terminal window resize and update status bar position
|
||||
*
|
||||
* @param fd File descriptor for terminal (STDOUT_FILENO)
|
||||
*/
|
||||
void check_console_resize(int fd);
|
||||
|
||||
/**
|
||||
* Update the status bar with Git information
|
||||
*
|
||||
* @param fd File descriptor for terminal (STDOUT_FILENO)
|
||||
* @param git_info The Git information to display in the status bar
|
||||
*/
|
||||
void update_status_bar(int fd, const char *git_info);
|
||||
|
||||
/**
|
||||
* Get the name of the parent and current directories from a path
|
||||
*
|
||||
* @param cwd The current working directory path
|
||||
* @param parent_dir_name Buffer to store the parent directory name
|
||||
* @param current_dir_name Buffer to store the current directory name
|
||||
* @param buf_size Size of the buffers
|
||||
*/
|
||||
void get_path_display(const char *cwd, char *parent_dir_name,
|
||||
char *current_dir_name, size_t buf_size);
|
||||
|
||||
/**
|
||||
* Initialize the terminal for raw mode
|
||||
*
|
||||
* @param orig_termios Original terminal settings to restore later
|
||||
* @return File descriptor for terminal
|
||||
*/
|
||||
int init_terminal(struct termios *orig_termios);
|
||||
|
||||
/**
|
||||
* Restore terminal to original settings
|
||||
*
|
||||
* @param fd File descriptor for terminal
|
||||
* @param orig_termios Original terminal settings
|
||||
*/
|
||||
void restore_terminal(int fd, struct termios *orig_termios);
|
||||
|
||||
/**
|
||||
* Get console dimensions
|
||||
*
|
||||
* @param fd File descriptor for terminal
|
||||
* @param width Pointer to store width
|
||||
* @param height Pointer to store height
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int get_console_dimensions(int fd, int *width, int *height);
|
||||
|
||||
#endif // SHELL_H
|
||||
70
include/structured_data.h
Normal file
70
include/structured_data.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* structured_data.h
|
||||
* Definitions for structured data representation and manipulation
|
||||
*/
|
||||
|
||||
#ifndef STRUCTURED_DATA_H
|
||||
#define STRUCTURED_DATA_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// Value types for structured data
|
||||
typedef enum {
|
||||
TYPE_STRING,
|
||||
TYPE_INT,
|
||||
TYPE_FLOAT,
|
||||
TYPE_SIZE // Special type for file sizes with units
|
||||
} ValueType;
|
||||
|
||||
// A single data value that can be of different types
|
||||
typedef struct {
|
||||
ValueType type;
|
||||
union {
|
||||
char *str_val;
|
||||
int int_val;
|
||||
float float_val;
|
||||
struct {
|
||||
double value;
|
||||
char unit[8];
|
||||
} size_val;
|
||||
} value;
|
||||
int is_highlighted; // Flag for highlighting in tables
|
||||
} DataValue;
|
||||
|
||||
// Table structure to hold rows and columns of data
|
||||
typedef struct {
|
||||
char **headers; // Column names
|
||||
int header_count; // Number of columns
|
||||
DataValue **rows; // Array of rows (each row is an array of DataValues)
|
||||
int row_count; // Current number of rows
|
||||
int row_capacity; // Allocated capacity for rows
|
||||
} TableData;
|
||||
|
||||
// Function to create a new table with the given headers
|
||||
TableData* create_table(char **headers, int header_count);
|
||||
|
||||
// Function to add a row to a table
|
||||
void add_table_row(TableData *table, DataValue *row);
|
||||
|
||||
// Function to free all memory associated with a table
|
||||
void free_table(TableData *table);
|
||||
|
||||
// Function to create a copy of a DataValue
|
||||
DataValue copy_data_value(const DataValue *src);
|
||||
|
||||
// Function to free a DataValue
|
||||
void free_data_value(DataValue *value);
|
||||
|
||||
// Function to filter a table based on a condition
|
||||
TableData* filter_table(TableData *input, char *field, char *op, char *value);
|
||||
|
||||
// Function to print a table to the console
|
||||
void print_table(TableData *table);
|
||||
|
||||
// Function to parse human-readable sizes
|
||||
long parse_size(const char *size_str);
|
||||
|
||||
// Function to extract size in bytes from a formatted size string
|
||||
long extract_size_bytes(const char *size_str);
|
||||
|
||||
#endif // STRUCTURED_DATA_H
|
||||
77
include/system_monitor.h
Normal file
77
include/system_monitor.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef SYSTEM_MONITOR_H
|
||||
#define SYSTEM_MONITOR_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <ncurses.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct {
|
||||
float cpu_percent;
|
||||
float gpu_percent;
|
||||
unsigned long gpu_memory_used;
|
||||
unsigned long gpu_memory_total;
|
||||
unsigned long memory_used;
|
||||
unsigned long memory_total;
|
||||
unsigned long disk_read;
|
||||
unsigned long disk_write;
|
||||
unsigned long net_rx;
|
||||
unsigned long net_tx;
|
||||
int process_count;
|
||||
} SystemStats;
|
||||
|
||||
typedef struct {
|
||||
WINDOW *main_win;
|
||||
WINDOW *header_win;
|
||||
WINDOW *stats_win;
|
||||
WINDOW *process_win;
|
||||
WINDOW *status_win;
|
||||
WINDOW *search_win;
|
||||
int terminal_height;
|
||||
int terminal_width;
|
||||
int selected_process;
|
||||
int refresh_rate;
|
||||
int process_scroll_offset;
|
||||
int search_mode;
|
||||
char search_buffer[256];
|
||||
int search_cursor;
|
||||
volatile sig_atomic_t resize_flag;
|
||||
} NCursesMonitor;
|
||||
|
||||
typedef struct {
|
||||
int pid;
|
||||
char name[256];
|
||||
float cpu_percent;
|
||||
unsigned long memory;
|
||||
char state;
|
||||
} ProcessInfo;
|
||||
|
||||
int init_ncurses_monitor(NCursesMonitor *monitor);
|
||||
int builtin_monitor(char **args);
|
||||
void display_dashboard(SystemStats *stats, ProcessInfo *processes,
|
||||
int proc_count);
|
||||
void get_system_stats(SystemStats *stats);
|
||||
int get_process_info(ProcessInfo *processes, int max_processes);
|
||||
void clear_screen(void);
|
||||
void move_cursor(int row, int col);
|
||||
void hide_cursor(void);
|
||||
void show_cursor(void);
|
||||
int kbhit(void);
|
||||
void draw_progress_bar(int percentage, int width);
|
||||
void format_progress_bar(int percentage, int width, char *buffer);
|
||||
void format_bytes(unsigned long bytes, char *buffer);
|
||||
void cleanup_ncurses_monitor(NCursesMonitor *monitor);
|
||||
void display_ncurses_dashboard(NCursesMonitor *monitor, SystemStats *stats,
|
||||
ProcessInfo *processes, int proc_count);
|
||||
void handle_monitor_input(NCursesMonitor *monitor, int ch);
|
||||
|
||||
#endif
|
||||
73
include/tab_complete.h
Normal file
73
include/tab_complete.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* tab_complete.h
|
||||
* Functions for tab completion and path suggestions
|
||||
*/
|
||||
|
||||
#ifndef TAB_COMPLETE_H
|
||||
#define TAB_COMPLETE_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Command context structure
|
||||
*/
|
||||
typedef struct {
|
||||
int is_after_pipe; // Flag if cursor is right after a pipe
|
||||
int is_filter_command; // Flag if current command is a filter command
|
||||
char cmd_before_pipe[64]; // Command before the pipe
|
||||
char filter_command[64]; // Current filter command
|
||||
char current_token[1024]; // Current token being typed
|
||||
int token_position; // Position within current token
|
||||
int token_index; // Index of current token in command
|
||||
int filter_arg_index; // Argument index for filter command
|
||||
int has_current_field; // Flag if current field is set
|
||||
int has_current_operator; // Flag if current operator is set
|
||||
char current_field[64]; // Current field if known
|
||||
char current_operator[16]; // Current operator if known
|
||||
} CommandContext;
|
||||
|
||||
typedef enum {
|
||||
ARG_TYPE_ANY, // Any argument
|
||||
ARG_TYPE_FILE, // Files only
|
||||
ARG_TYPE_DIRECTORY, // Directories only
|
||||
ARG_TYPE_BOOKMARK, // Bookmark names
|
||||
ARG_TYPE_ALIAS, // Alias names
|
||||
ARG_TYPE_BOTH, // Both files and directories
|
||||
ARG_TYPE_FAVORITE_CITY,
|
||||
ARG_TYPE_THEME,
|
||||
ARG_TYPE_COMMAND,
|
||||
} ArgumentType;
|
||||
|
||||
/**
|
||||
* Structure for command argument type information
|
||||
*/
|
||||
typedef struct {
|
||||
char *command; // Command name
|
||||
ArgumentType arg_type; // Expected argument type
|
||||
char *description; // Optional description
|
||||
int strict_match; // If 1, only show suggestions of the expected type
|
||||
// If 0, show suggestions of expected type but also allow
|
||||
// other matches
|
||||
} CommandArgInfo;
|
||||
|
||||
/**
|
||||
* Structure for returning multiple suggestions
|
||||
*/
|
||||
typedef struct {
|
||||
char **items; // Array of suggestion strings
|
||||
int count; // Number of suggestions
|
||||
int current_index; // Current index for cycling through suggestions
|
||||
} SuggestionList;
|
||||
|
||||
// Tab completion functions
|
||||
char *get_tab_completion(const char *buffer);
|
||||
SuggestionList *get_suggestion_list(const char *buffer, const char *prefix);
|
||||
void free_suggestion_list(SuggestionList *list);
|
||||
|
||||
// Initialize tab completion system
|
||||
void init_tab_completion(void);
|
||||
|
||||
// Shutdown tab completion system
|
||||
void shutdown_tab_completion(void);
|
||||
|
||||
#endif // TAB_COMPLETE_H
|
||||
92
include/themes.h
Normal file
92
include/themes.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef THEMES_H
|
||||
#define THEMES_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef struct {
|
||||
// Standard console colors
|
||||
WORD PRIMARY_COLOR; // Main text color
|
||||
WORD SECONDARY_COLOR; // Secondary text color
|
||||
WORD ACCENT_COLOR; // Color for highlights/important elements
|
||||
WORD SUCCESS_COLOR; // Success messages
|
||||
WORD ERROR_COLOR; // Error messages
|
||||
WORD WARNING_COLOR; // Warning messages
|
||||
|
||||
WORD INVALID_COMMAND_COLOR; // unrecognized command
|
||||
|
||||
// UI element colors
|
||||
WORD HEADER_COLOR; // Headers and titles
|
||||
WORD STATUS_BAR_COLOR; // Status bar background
|
||||
WORD STATUS_TEXT_COLOR; // Status bar text
|
||||
WORD PROMPT_COLOR; // Command prompt
|
||||
|
||||
// File system colors
|
||||
WORD DIRECTORY_COLOR; // Directory names
|
||||
WORD EXECUTABLE_COLOR; // Executable files
|
||||
WORD TEXT_FILE_COLOR; // Text files
|
||||
WORD IMAGE_FILE_COLOR; // Image files
|
||||
WORD CODE_FILE_COLOR; // Code files (non-executable)
|
||||
WORD ARCHIVE_FILE_COLOR; // Archive files
|
||||
|
||||
// Syntax highlighting colors
|
||||
WORD SYNTAX_KEYWORD; // Keywords in syntax highlighting
|
||||
WORD SYNTAX_STRING; // Strings in syntax highlighting
|
||||
WORD SYNTAX_COMMENT; // Comments in syntax highlighting
|
||||
WORD SYNTAX_NUMBER; // Numbers in syntax highlighting
|
||||
WORD SYNTAX_PREPROCESSOR; // Preprocessor in syntax highlighting
|
||||
|
||||
// ANSI true color definitions (for modern terminals)
|
||||
char ANSI_BASE[20]; // Base color
|
||||
char ANSI_SURFACE[20]; // Surface color
|
||||
char ANSI_OVERLAY[20]; // Overlay color
|
||||
char ANSI_MUTED[20]; // Muted color
|
||||
char ANSI_SUBTLE[20]; // Subtle color
|
||||
char ANSI_TEXT[20]; // Text color
|
||||
char ANSI_LOVE[20]; // Love/Red color
|
||||
char ANSI_GOLD[20]; // Gold color
|
||||
char ANSI_ROSE[20]; // Rose/pink color
|
||||
char ANSI_PINE[20]; // Pine color
|
||||
char ANSI_FOAM[20]; // Foam color
|
||||
char ANSI_IRIS[20]; // Iris color
|
||||
char ANSI_HIGHLIGHT[20]; // Highlight color
|
||||
|
||||
char ANSI_INVALID_COMMAND[20];
|
||||
|
||||
// Flag to indicate if ANSI colors should be used
|
||||
BOOL use_ansi_colors;
|
||||
|
||||
// Name of the theme
|
||||
char name[32];
|
||||
} ShellTheme;
|
||||
|
||||
// Initialize theme system
|
||||
void init_theme_system(void);
|
||||
|
||||
// Shutdown theme system
|
||||
void shutdown_themes(void);
|
||||
|
||||
// Initialize themes for shell startup
|
||||
void init_themes(void);
|
||||
|
||||
// Load a theme by name
|
||||
int load_theme(const char *theme_name);
|
||||
|
||||
// Apply current theme settings
|
||||
void apply_current_theme(void);
|
||||
|
||||
// Get current theme
|
||||
const ShellTheme *get_current_theme(void);
|
||||
|
||||
// List available themes
|
||||
void list_available_themes(void);
|
||||
|
||||
// Get theme names for tab completion
|
||||
char **get_theme_names(int *theme_count);
|
||||
|
||||
// Command handler for "theme" command
|
||||
int lsh_theme(char **args);
|
||||
|
||||
// Current active theme
|
||||
extern ShellTheme current_theme;
|
||||
|
||||
#endif // THEMES_H
|
||||
38
include/timer.h
Normal file
38
include/timer.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* timer.h
|
||||
* Header for command execution timer functionality
|
||||
*/
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* Format a time interval in milliseconds to a readable string
|
||||
*
|
||||
* @param ms Time in milliseconds
|
||||
* @param buffer Buffer to store formatted time
|
||||
* @param buffer_size Size of the buffer
|
||||
*/
|
||||
void format_time(double ms, char *buffer, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* Implementation of the timer command
|
||||
* Usage: timer COMMAND [ARGS...]
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return 1 to continue, 0 to exit
|
||||
*/
|
||||
int lsh_timer(char **args);
|
||||
|
||||
/**
|
||||
* Implementation of the time command (alias for timer)
|
||||
* Usage: time COMMAND [ARGS...]
|
||||
*
|
||||
* @param args Command arguments
|
||||
* @return 1 to continue, 0 to exit
|
||||
*/
|
||||
int lsh_time(char **args);
|
||||
|
||||
#endif // TIMER_H
|
||||
8
include/weather.h
Normal file
8
include/weather.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef WEATHER_H
|
||||
#define WEATHER_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int lsh_weather(char **args);
|
||||
|
||||
#endif // WEATHER_H
|
||||
Reference in New Issue
Block a user