Adding splitting screen and buffer switching
This commit is contained in:
+51
-1
@@ -1,8 +1,58 @@
|
||||
/**
|
||||
* @file buffer.h
|
||||
* @brief Buffer management for handling multiple open files
|
||||
*/
|
||||
|
||||
#ifndef BUFFER_H_
|
||||
#define BUFFER_H_
|
||||
|
||||
#include "data.h"
|
||||
|
||||
int new_buffer(enum buffer_type type, char * filename, int width, int height);
|
||||
/**
|
||||
* @brief Creates a new buffer for a file
|
||||
* @param filename Path to the file
|
||||
* @return Buffer ID on success, -1 on failure
|
||||
*/
|
||||
int bufferCreate(const char *filename);
|
||||
|
||||
/**
|
||||
* @brief Switches to a specific buffer by ID
|
||||
* @param buffer_id The buffer ID to switch to
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int bufferSwitch(int buffer_id);
|
||||
|
||||
struct buffer_t *bufferFindById(int buffer_id);
|
||||
|
||||
/**
|
||||
* @brief Closes a buffer by ID
|
||||
* @param buffer_id The buffer ID to close
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int bufferClose(int buffer_id);
|
||||
|
||||
/**
|
||||
* @brief Gets the current active buffer
|
||||
* @return Pointer to current buffer_t, NULL if none
|
||||
*/
|
||||
struct buffer_t *bufferGetCurrent(void);
|
||||
|
||||
/**
|
||||
* @brief Lists all open buffers
|
||||
* @return Number of open buffers
|
||||
*/
|
||||
int bufferListAll(void);
|
||||
|
||||
/**
|
||||
* @brief Saves current buffer to disk
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int bufferSave(void);
|
||||
|
||||
/**
|
||||
* @brief Saves all buffers to disk
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int bufferSaveAll(void);
|
||||
|
||||
#endif
|
||||
|
||||
+34
-26
@@ -3,45 +3,53 @@
|
||||
|
||||
#include "lisp.h"
|
||||
|
||||
// Mouvement
|
||||
|
||||
Lisp moveCursor(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp mapKey(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
void registerBuiltin(char * key_sequence, LispCFunc f);
|
||||
|
||||
Lisp editorQuit(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp l_editorSave(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp l_editorInsertNewLine(Lisp args, LispError* e, LispContext ctx);
|
||||
|
||||
Lisp moveCursorBeginLine(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp moveCursorEndLine(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp l_editorInserTab(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp deletePreviousChar(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorMoveCursorPageUp(Lisp args, LispError* e, LispContext ctx);
|
||||
|
||||
Lisp editorMoveCursorPageDown(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx);
|
||||
// Text editing
|
||||
|
||||
Lisp l_editorInsertNewLine(Lisp args, LispError* e, LispContext ctx);
|
||||
Lisp l_editorInserTab(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp deletePreviousChar(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp addPackage(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorSetPrefix(Lisp args, LispError *e, LispContext ctx);
|
||||
// Editor
|
||||
|
||||
Lisp editorQuit(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp l_editorSave(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp editorSetPrefix(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp editorPrefix(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp mapKey(Lisp args, LispError *e, LispContext ctx);
|
||||
void registerBuiltin(char * key_sequence, LispCFunc f);
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp addPackage(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
|
||||
// Buffer
|
||||
|
||||
Lisp editorSwitchNextBuffer(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp bufferFind_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
|
||||
// Pane
|
||||
|
||||
Lisp l_editorSplitScreenVertical(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp editorSwitchNextPane(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp editorUnifiedPanes(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Other
|
||||
|
||||
void free_structs(void);
|
||||
|
||||
|
||||
+51
-13
@@ -13,12 +13,50 @@
|
||||
* \param
|
||||
* */
|
||||
|
||||
typedef struct erow {
|
||||
typedef struct frow {
|
||||
int size; /**< Size of the line */
|
||||
int rsize; /**< Size of the render line */
|
||||
char *chars; /**< Characters of the line */
|
||||
char *render; /**< The actual line we will print */
|
||||
} erow;
|
||||
} frow;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Split modes for screen layout
|
||||
*/
|
||||
typedef enum {
|
||||
SPLIT_NONE = 0, // Single buffer fullscreen
|
||||
SPLIT_VERTICAL, // Left-right split
|
||||
SPLIT_HORIZONTAL // Top-bottom split
|
||||
} SplitMode;
|
||||
|
||||
/**
|
||||
* @brief Represents an editor viewport/pane
|
||||
*/
|
||||
typedef struct {
|
||||
int buffer_id; // Which buffer this pane displays
|
||||
int start_row; // Starting row on screen
|
||||
int start_col; // Starting column on screen
|
||||
int height; // Height of this pane
|
||||
int width; // Width of this pane
|
||||
int cursor_x; // Local cursor x in this pane
|
||||
int cursor_y; // Local cursor y in this pane
|
||||
int rx, ry;
|
||||
int row_offset; // Scroll offset for rows
|
||||
int col_offset; // Scroll offset for columns
|
||||
int is_active; // Is this pane currently active
|
||||
} EditorPane;
|
||||
|
||||
/**
|
||||
* @brief Screen layout manager
|
||||
*/
|
||||
typedef struct {
|
||||
SplitMode mode;
|
||||
EditorPane *panes;
|
||||
int num_panes;
|
||||
int active_pane; // Index of active pane
|
||||
} ScreenLayout;
|
||||
|
||||
|
||||
typedef struct theme {
|
||||
char *BACKGROUND_COLOR;
|
||||
@@ -31,7 +69,7 @@ typedef struct theme {
|
||||
|
||||
} theme_t;
|
||||
|
||||
enum editorStatus_e {
|
||||
enum bufferStatus_e {
|
||||
IDLE,
|
||||
READ_ONLY,
|
||||
READ_AND_WRITE,
|
||||
@@ -60,8 +98,14 @@ struct buffer_t {
|
||||
enum buffer_type type;
|
||||
int buffer_id;
|
||||
int width, height;
|
||||
int x, y; /**< Position of the buffer*/
|
||||
int x, y; /**< Position in the buffer (cursor) */
|
||||
frow *row;
|
||||
int numrows;
|
||||
char *filename;
|
||||
enum bufferStatus_e state;
|
||||
int dirty; /**< Has this buffer been modified since last save */
|
||||
int row_offset; /**< Scroll offset for rows in this buffer */
|
||||
int col_offset; /**< Scroll offset for columns in this buffer */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -69,17 +113,12 @@ struct buffer_t {
|
||||
* \brief Containing our editor state.
|
||||
*/
|
||||
struct editorConfig {
|
||||
int cursor_x, cursor_y; /**< Cursor position */
|
||||
int rx; /**< Position in the render*/
|
||||
int row_offset; /**< Position scroll of lines */
|
||||
int col_offset; /**< Position scroll of colomns*/
|
||||
int screenrows; /**< Terminal height*/
|
||||
int screencols; /**< Terminal width*/
|
||||
int numrows; /**< Number of rows contained */
|
||||
erow *row; /**< Store all the rows printed */
|
||||
|
||||
ScreenLayout layout;
|
||||
|
||||
int dirty;
|
||||
char *filename;
|
||||
enum editorStatus_e state;
|
||||
int prefix_state;
|
||||
char status_msg[80];
|
||||
time_t status_msg_time;
|
||||
@@ -102,7 +141,6 @@ struct editorConfig {
|
||||
int number_of_prefix;
|
||||
|
||||
struct buffer_t buffers[64];
|
||||
struct buffer_t ***screen_layout; /**< Which buffer is the current cell*/
|
||||
int number_of_buffer;
|
||||
|
||||
theme_t theme;
|
||||
|
||||
+3
-3
@@ -2,11 +2,11 @@
|
||||
#define EDITOR_OP_H_
|
||||
|
||||
#include "data.h"
|
||||
void editorInsertChar(int c);
|
||||
void bufferInsertChar(int c);
|
||||
|
||||
void editorInsertNewLine();
|
||||
void bufferInsertNewLine();
|
||||
|
||||
void editorDelChar();
|
||||
void bufferDelChar();
|
||||
|
||||
void editorSetStatusMessage(const char *fmt, ...);
|
||||
|
||||
|
||||
+3
-3
@@ -8,15 +8,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
char *editorRowsToString(int *buffer_len);
|
||||
char *bufferRowsToString(struct buffer_t *buf,int *buffer_len);
|
||||
|
||||
|
||||
void editorCloseFile(void);
|
||||
|
||||
void editorOpen(char *filename);
|
||||
void editorOpen(struct buffer_t *buffer);
|
||||
|
||||
void editorSave();
|
||||
|
||||
void editorFind();
|
||||
void bufferFind(struct buffer_t *buf);
|
||||
|
||||
#endif // FILE_IO_H_
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#ifndef OUTPUT_H_
|
||||
#define OUTPUT_H_
|
||||
|
||||
#include "append_buffer.h"
|
||||
#include "data.h"
|
||||
#include "define.h"
|
||||
#include "row_op.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
|
||||
+9
-9
@@ -8,22 +8,22 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int editorRowCxToRx(erow *row, int cursor_x);
|
||||
int bufferRowCxToRx(frow *row, int cursor_x);
|
||||
|
||||
int editorRowRxToCx(erow *row, int rx);
|
||||
int bufferRowRxToCx(frow *row, int rx);
|
||||
|
||||
void editorUpdateRow(erow *row);
|
||||
void bufferUpdatfrow(frow *row);
|
||||
|
||||
void editorInsertRow(int at, char *s, size_t len);
|
||||
void bufferInsertRow(struct buffer_t *buffer, int at, char *s, size_t len);
|
||||
|
||||
void editorFreeRow(erow *row);
|
||||
void bufferFrefrow(frow *row);
|
||||
|
||||
void editorDelRow(int at);
|
||||
void bufferDelRow(struct buffer_t *buffer, int at);
|
||||
|
||||
void editorRowInsertChar(erow *row, int at, int c);
|
||||
void bufferRowInsertChar(struct buffer_t *buffer, frow *row, int at, int c);
|
||||
|
||||
void editorRowAppendString(erow *row, char *s, size_t len);
|
||||
void bufferRowAppendString(struct buffer_t *buffer, frow *row, char *s, size_t len);
|
||||
|
||||
void editorRowDelchar(erow *row, int at);
|
||||
void bufferRowDelchar(struct buffer_t *buffer, frow *row, int at);
|
||||
|
||||
#endif // ROW_OP_H_
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @file split_screen.h
|
||||
* @brief Split screen management for displaying multiple buffers
|
||||
*/
|
||||
|
||||
#ifndef SPLIT_SCREEN_H_
|
||||
#define SPLIT_SCREEN_H_
|
||||
|
||||
#include "data.h"
|
||||
|
||||
/**
|
||||
* @brief Initializes split screen system
|
||||
*/
|
||||
void splitScreenInit(void);
|
||||
|
||||
/**
|
||||
* @brief Splits screen vertically (left-right)
|
||||
* @param buffer_id_left Buffer ID for left pane
|
||||
* @param buffer_id_right Buffer ID for right pane
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int splitScreenVertical(int buffer_id_left, int buffer_id_right);
|
||||
|
||||
/**
|
||||
* @brief Splits screen horizontally (top-bottom)
|
||||
* @param buffer_id_top Buffer ID for top pane
|
||||
* @param buffer_id_bottom Buffer ID for bottom pane
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int splitScreenHorizontal(int buffer_id_top, int buffer_id_bottom);
|
||||
|
||||
/**
|
||||
* @brief Returns to single buffer fullscreen
|
||||
*/
|
||||
void splitScreenUnify(void);
|
||||
|
||||
/**
|
||||
* @brief Switches active pane (focus moves between splits)
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int splitScreenSwitchPane(void);
|
||||
|
||||
/**
|
||||
* @brief Updates the active pane's buffer
|
||||
* @param buffer_id New buffer ID for active pane
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int splitScreenSetPaneBuffer(int buffer_id);
|
||||
|
||||
/**
|
||||
* @brief Gets current screen layout
|
||||
* @return Pointer to current ScreenLayout
|
||||
*/
|
||||
ScreenLayout *splitScreenGetLayout(void);
|
||||
|
||||
/**
|
||||
* @brief Gets active pane
|
||||
* @return Pointer to active EditorPane
|
||||
*/
|
||||
EditorPane *splitScreenGetActivePane(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user