From 7bb48aabe99de0544c0184cb1320ca4193f47b2a Mon Sep 17 00:00:00 2001 From: Jonathan Griffitts Date: Fri, 17 May 2024 16:15:02 -0600 Subject: [PATCH 1/2] Tweak the Terminal widget API, remove some redundant methods --- CMakeLists.txt | 2 +- fltk | 2 +- include/cfl_group.h | 49 +++++++++----- src/cfl_group.cpp | 162 ++++++++++++++++++++++++-------------------- 4 files changed, 122 insertions(+), 93 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a579762..218c3d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.5) set(CFLTK_PROJECT_VERSION 1.4.30) project( diff --git a/fltk b/fltk index 324fcfc..da58045 160000 --- a/fltk +++ b/fltk @@ -1 +1 @@ -Subproject commit 324fcfcb6228aeb24af8c50d548438e5f1d174b7 +Subproject commit da58045c23954b53d508c46ccf9dd4433bc94f9a diff --git a/include/cfl_group.h b/include/cfl_group.h index 67da6f7..cca6a02 100644 --- a/include/cfl_group.h +++ b/include/cfl_group.h @@ -254,12 +254,6 @@ void Fl_Terminal_set_display_columns(Fl_Terminal *self, int set); int Fl_Terminal_display_rows(Fl_Terminal const *self); -void Fl_Terminal_set_display_rows(Fl_Terminal *self, int set); - -int Fl_Terminal_history_lines(Fl_Terminal const *self); - -void Fl_Terminal_set_history_lines(Fl_Terminal *self, int set); - int Fl_Terminal_history_rows(Fl_Terminal const *self); void Fl_Terminal_set_history_rows(Fl_Terminal *self, int set); @@ -319,6 +313,20 @@ int Fl_Terminal_scrollbar_size(Fl_Terminal const *self); void Fl_Terminal_set_scrollbar_size(Fl_Terminal *self, int set); +// int Fl_Terminal_hscrollbar_actual_size(Fl_Terminal const *self); + +// int Fl_Terminal_hscrollbar_size(Fl_Terminal const *self); + +// void Fl_Terminal_set_hscrollbar_size(Fl_Terminal *self, int set); + +// int Fl_Terminal_hscroll_col(Fl_Terminal const *self); + +// void Fl_Terminal_set_hscroll_col(Fl_Terminal *self, int set); + +int Fl_Terminal_hscrollbar_style(Fl_Terminal const *self); // Actually returns enum HScrollbarStyle + +void Fl_Terminal_set_hscrollbar_style(Fl_Terminal *self, int set); + unsigned Fl_Terminal_selection_bg_color(Fl_Terminal const *self ); // Actually Fl_Color @@ -374,6 +382,17 @@ int Fl_Terminal_text_size(Fl_Terminal const *self); void Fl_Terminal_set_text_size(Fl_Terminal *self, int set); +const char* Fl_Terminal_text(Fl_Terminal const *self, int lines_below_cursor); // Argument is bool + +const char *Fl_Terminal_selection_text(Fl_Terminal const *self); +int Fl_Terminal_selection_text_len(Fl_Terminal const *self); + +//---------------------------------------------------------------------- +/// Access to terminal widget's vertical and horizontal scrollbar +typedef void Fl_Terminal_Scrollbar; +Fl_Terminal_Scrollbar * Fl_Terminal_scrollbar(Fl_Terminal *self); +Fl_Terminal_Scrollbar * Fl_Terminal_hscrollbar(Fl_Terminal *self); + //---------------------------------------------------------------------- /// Utf8Char class, used to describe characters in the terminal ring buffer typedef void Fl_Terminal_Utf8Char; @@ -416,28 +435,22 @@ Fl_Terminal_Utf8Char *Fl_Terminal_Utf8Char_new_obj(unsigned char c); //---------------------------------------------------------------------- // The following are protected functions used to access ring buffer text: -const char *Fl_Terminal_selection_text(Fl_Terminal const *self); - int Fl_Terminal_disp_erow(Fl_Terminal const *self); -int Fl_Terminal_disp_rows(Fl_Terminal const *self); - -int Fl_Terminal_disp_cols(Fl_Terminal const *self); - int Fl_Terminal_disp_srow(Fl_Terminal const *self); -int Fl_Terminal_hist_cols(Fl_Terminal const *self); - int Fl_Terminal_hist_erow(Fl_Terminal const *self); -int Fl_Terminal_hist_rows(Fl_Terminal const *self); - int Fl_Terminal_hist_srow(Fl_Terminal const *self); int Fl_Terminal_hist_use(Fl_Terminal const *self); int Fl_Terminal_hist_use_srow(Fl_Terminal const *self); +int Fl_Terminal_h_to_row(Fl_Terminal const *self, int H); + +int Fl_Terminal_w_to_col(Fl_Terminal const *self, int W); + int Fl_Terminal_is_inside_selection( Fl_Terminal const *self, int row, int col ); // Actual return type is bool @@ -447,8 +460,6 @@ int Fl_Terminal_is_selection(Fl_Terminal const *self int Fl_Terminal_offset(Fl_Terminal const *self); -int Fl_Terminal_ring_cols(Fl_Terminal const *self); - int Fl_Terminal_ring_erow(Fl_Terminal const *self); int Fl_Terminal_ring_srow(Fl_Terminal const *self); @@ -472,6 +483,8 @@ Fl_Terminal_u8c_ring_row(Fl_Terminal const *self, int grow); const unsigned Fl_Terminal_Utf8Char_size(void); +void Fl_free_str(const char *str); + // todo: Protected methods still unimplemented here: // current_style, h_to_row, selection_extend, w_to_col, walk_selection, vscroll_width diff --git a/src/cfl_group.cpp b/src/cfl_group.cpp index d828126..ec658d7 100644 --- a/src/cfl_group.cpp +++ b/src/cfl_group.cpp @@ -354,10 +354,10 @@ struct Fl_Terminal_Derived : public Widget_Derived { unsigned attr_bgcolor(Fl_Terminal const *grp) const { return ((Fl_Terminal::Utf8Char *) this)->attr_bg_color(grp); }; unsigned attr_fgcolor(Fl_Terminal const *grp) const { return ((Fl_Terminal::Utf8Char *) this)->attr_fg_color(grp); }; unsigned char attrib(void) const { - return ((Fl_Terminal::Utf8Char *) this)->attrib(); + return ((Fl_Terminal::Utf8Char *) this)->attrib(); }; unsigned bgcolor(void) const { - return ((Fl_Terminal::Utf8Char *) this)->bgcolor(); + return ((Fl_Terminal::Utf8Char *) this)->bgcolor(); }; unsigned fgcolor(void) const { return ((Fl_Terminal::Utf8Char *) this)->fgcolor(); }; int is_char(char c) const { return ((Fl_Terminal::Utf8Char *) this)->is_char(c); }; // boolean @@ -370,9 +370,9 @@ struct Fl_Terminal_Derived : public Widget_Derived { static const unsigned size = sizeof(Fl_Terminal::Utf8Char); }; - const char *get_selection_text() const { - return this->selection_text(); - } + // const char *get_selection_text() const { + // return this->selection_text(); + // } void clear_mouse_selection(void) { Fl_Terminal::clear_mouse_selection(); @@ -456,31 +456,26 @@ struct Fl_Terminal_Derived : public Widget_Derived { // returns bool false for no selection - int get_selection(int &srow, int &scol, int &erow, int &ecol) { + int get_selection(int &srow, int &scol, int &erow, int &ecol) { return Fl_Terminal::get_selection(srow, scol, erow, ecol); } + int w_to_col(int W) const { + return Fl_Terminal::w_to_col(W); + } + int h_to_row(int H) const { + return Fl_Terminal::h_to_row(H); + }; + int disp_erow(void) const { return Fl_Terminal::disp_erow(); } - int disp_rows(void) const { - return Fl_Terminal::disp_rows(); - } - int disp_cols(void) const { - return Fl_Terminal::disp_cols(); - } int disp_srow(void) const { return Fl_Terminal::disp_srow(); } - int hist_cols(void) const { - return Fl_Terminal::hist_cols(); - } int hist_erow(void) const { return Fl_Terminal::hist_erow(); } - int hist_rows(void) const { - return Fl_Terminal::hist_rows(); - } int hist_srow(void) const { return Fl_Terminal::hist_srow(); } @@ -499,9 +494,6 @@ struct Fl_Terminal_Derived : public Widget_Derived { int offset(void) const { return Fl_Terminal::offset(); } - int ring_cols(void) const { - return Fl_Terminal::ring_cols(); - } int ring_erow(void) const { return Fl_Terminal::ring_erow(); } @@ -624,19 +616,6 @@ int Fl_Terminal_display_rows(Fl_Terminal const *self) { return ret; } -void Fl_Terminal_set_display_rows(Fl_Terminal *self, int set) { - LOCK(self->display_rows(set)); -} - -int Fl_Terminal_history_lines(Fl_Terminal const *self) { - LOCK(auto ret = self->history_lines()); - return ret; -} - -void Fl_Terminal_set_history_lines(Fl_Terminal *self, int set) { - LOCK(self->history_lines(set)); -} - int Fl_Terminal_history_rows(Fl_Terminal const *self) { LOCK(auto ret = self->history_rows()); return ret; @@ -752,6 +731,15 @@ void Fl_Terminal_set_scrollbar_size(Fl_Terminal *self, int set) { LOCK(self->scrollbar_size(set)); } +int Fl_Terminal_hscrollbar_style(Fl_Terminal const *self) { // Actually returns enum ScrollbarStyle + LOCK(auto ret = self->hscrollbar_style()); + return ret; +} + +void Fl_Terminal_set_hscrollbar_style(Fl_Terminal *self, int set) { + LOCK(self->hscrollbar_style((Fl_Terminal::ScrollbarStyle) set)); +} + unsigned Fl_Terminal_selection_bg_color(Fl_Terminal const *self ) { // Actually returns Fl_Color LOCK(auto ret = self->selectionbgcolor()); @@ -863,8 +851,9 @@ void Fl_Terminal_set_text_size(Fl_Terminal *self, int set) { LOCK(self->textsize(set)); } -/// printf not used by Rust but might be useful for C programs using this -/// interface +/// printf is not used by Rust but might be useful for C programs using this +/// interface. +/// String is limited to no longer than 1024 characters including NULL terminator. void Fl_Terminal_printf(Fl_Terminal *self, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -872,6 +861,44 @@ void Fl_Terminal_printf(Fl_Terminal *self, const char *fmt, ...) { va_end(ap); } +/** + Return a string copy of all lines in the terminal (including history). + The returned string is allocated with strdup(3), which the caller must free. + + If \p 'lines_below_cursor' is false (default), lines below the cursor on down + to the bottom of the display are ignored, and not included in the returned string. + + If \p 'lines_below_cursor' is true, then all lines in the display are returned + including any below the cursor, even if all are blank. +*/ +const char* Fl_Terminal_text(Fl_Terminal const *self, int lines_below_cursor) { // Argument is bool + LOCK(auto ret = self->text(lines_below_cursor)); + return ret; +} + +const char *Fl_Terminal_selection_text(const Fl_Terminal *self) { + LOCK(auto ret = self->selection_text()); + return ret; +} + +int Fl_Terminal_selection_text_len(const Fl_Terminal *self) { + LOCK(auto ret = self->selection_text_len()); + return ret; +} + + + +///////////////////////////////////////////////////////////////////////////////////////// +// Access to terminal widget's vertical and horizontal scrollbar +Fl_Terminal_Scrollbar * Fl_Terminal_scrollbar(Fl_Terminal *self) { + return self->scrollbar; +} + +Fl_Terminal_Scrollbar * Fl_Terminal_hscrollbar(Fl_Terminal *self) { + return self->hscrollbar; +} + + ///////////////////////////////////////////////////////////////////////////////////////// // Protected Fl_Terminal methods: @@ -882,13 +909,13 @@ void Fl_Terminal_clear_mouse_selection(Fl_Terminal *self) { /// Set the cursor's current column position on the screen. void Fl_Terminal_set_cursor_col(Fl_Terminal *self, int val) { - // (Note: the cursor_col() getter is public, not protected) + // (Note: the cursor_col() getter is public, not protected) LOCK(((Fl_Terminal_Derived *) self)->set_cursor_col(val)); } -/// Set the cursor's current row position on the screen. +/// Set the cursor's current row position on the screen. void Fl_Terminal_set_cursor_row(Fl_Terminal *self, int val) { - // (Note: the cursor_row() getter is public, not protected) + // (Note: the cursor_row() getter is public, not protected) LOCK(((Fl_Terminal_Derived *) self)->set_cursor_row(val)); } @@ -960,6 +987,15 @@ void Fl_Terminal_delete_rows(Fl_Terminal *self, int count) { LOCK(((Fl_Terminal_Derived *) self)->delete_rows(count)); } +int Fl_Terminal_h_to_row(Fl_Terminal const *self, int H) { + LOCK(auto ret = ((Fl_Terminal_Derived *)self)->h_to_row(H)); + return ret; +} + +int Fl_Terminal_w_to_col(Fl_Terminal const *self, int W) { + LOCK(auto ret = ((Fl_Terminal_Derived *)self)->w_to_col(W)); + return ret; +} /// Places four integers (srow, scol, erow, ecol) into the provided buffer, which should be a uint32_t[4] array /// bool return falue is FALSE if no selection exists @@ -1069,57 +1105,35 @@ Fl_Terminal_Utf8Char * Fl_Terminal_Utf8Char_new_obj(unsigned char c) { } +// const char *Fl_Terminal_selection_text(const Fl_Terminal *self) { +// LOCK(auto ret = ((Fl_Terminal_Derived *)self)->get_selection_text()); +// return ret; +// } + + ///////////////////////////////////////////////////////////////////////////////////////// // The following are protected functions used to access ring buffer text: /// Return text selection (for copy()/paste() operations) -const char *Fl_Terminal_selection_text(const Fl_Terminal *self) { - LOCK(auto ret = ((Fl_Terminal_Derived *)self)->get_selection_text()); - return ret; -} -/// Return the ending row# in the display area. +/// Return the ending row# in the display area. int Fl_Terminal_disp_erow(Fl_Terminal const *self) { LOCK(auto ret = ((Fl_Terminal_Derived *) self)->disp_erow()); return ret; } -/// Return the number of rows in the display area. -int Fl_Terminal_disp_rows(Fl_Terminal const *self) { - LOCK(auto ret = ((Fl_Terminal_Derived *) self)->disp_rows()); - return ret; -} - -/// Return the number of columns in the display area. -int Fl_Terminal_disp_cols(Fl_Terminal const *self) { - LOCK(auto ret = ((Fl_Terminal_Derived *) self)->disp_cols()); - return ret; -} - /// Return the starting row# in the display area. int Fl_Terminal_disp_srow(Fl_Terminal const *self) { LOCK(auto ret = ((Fl_Terminal_Derived *) self)->disp_srow()); return ret; } -/// Return the number of columns in the scrollback history. -int Fl_Terminal_hist_cols(Fl_Terminal const *self) { - LOCK(auto ret = ((Fl_Terminal_Derived *) self)->hist_cols()); - return ret; -} - /// Return the ending row# of the scrollback history. int Fl_Terminal_hist_erow(Fl_Terminal const *self) { LOCK(auto ret = ((Fl_Terminal_Derived *) self)->hist_erow()); return ret; } -/// Return the number of rows in the scrollback history. -int Fl_Terminal_hist_rows(Fl_Terminal const *self) { - LOCK(auto ret = ((Fl_Terminal_Derived *) self)->hist_rows()); - return ret; -} - /// Return the starting row# of the scrollback history. int Fl_Terminal_hist_srow(Fl_Terminal const *self) { LOCK(auto ret = ((Fl_Terminal_Derived *) self)->hist_srow()); @@ -1161,11 +1175,6 @@ int Fl_Terminal_offset(Fl_Terminal const *self) { return ret; } -/// Return the number of columns in the ring buffer. -int Fl_Terminal_ring_cols(Fl_Terminal const *self) { - LOCK(auto ret = ((Fl_Terminal_Derived *) self)->ring_cols()); - return ret; -} /// Return the ending row# in the ring buffer (Always ring_rows()-1) int Fl_Terminal_ring_erow(Fl_Terminal const *self) { @@ -1231,3 +1240,10 @@ const unsigned Fl_Terminal_Utf8Char_size(void) { } GROUP_DEFINE(Fl_Terminal) + + +#include +// Free up string that was allocated in C++ +void Fl_free_str(const char *str) { + if (str) free((void *) str); +} From f35be289453085a9e196156658da2c714fb02e28 Mon Sep 17 00:00:00 2001 From: Jonathan Griffitts Date: Fri, 24 May 2024 12:06:18 -0600 Subject: [PATCH 2/2] Change include from obsolete malloc.h to stdlib.h --- CMakeLists.txt | 2 +- src/cfl_group.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 218c3d7..a579762 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.0) set(CFLTK_PROJECT_VERSION 1.4.30) project( diff --git a/src/cfl_group.cpp b/src/cfl_group.cpp index ec658d7..bcdc9c3 100644 --- a/src/cfl_group.cpp +++ b/src/cfl_group.cpp @@ -1242,7 +1242,7 @@ const unsigned Fl_Terminal_Utf8Char_size(void) { GROUP_DEFINE(Fl_Terminal) -#include +#include // Free up string that was allocated in C++ void Fl_free_str(const char *str) { if (str) free((void *) str);