60 offset += cl->len + 1;
63 char *buf_str =
nullptr;
69 if (sel[0] <= cl->len && sel[1] >= 0) {
70 int sta =
max_ii(sel[0], 0);
71 int end =
min_ii(sel[1], cl->len);
80 sel[0] -= cl->len + 1;
81 sel[1] -= cl->len + 1;
102 if (buf ==
nullptr) {
127 del_end = std::min(del_end, cl->
len);
129 const int len = del_end - del_start;
130 memmove(cl->
line + cl->
len - del_end, cl->
line + cl->
len - del_start, del_start);
192 else if (cursor > cl->
len) {
193 cursor_new = cl->
len;
199 if (cursor_new == cl->
cursor) {
208static void console_lb_debug__internal(
ListBase *lb)
213 for (cl = lb->
first; cl; cl = cl->
next) {
219static void console_history_debug(
const bContext *
C)
223 console_lb_debug__internal(&sc->
history);
265 const int str_len = strlen(
str);
306 int new_len =
len + 1;
308 int new_len = (
len + 1) * 2;
346 offset += cl->
len + 1;
355 *r_cl_offset = offset;
356 *r_col = offset -
pos;
370 {
LINE_BEGIN,
"LINE_BEGIN", 0,
"Line Begin",
""},
371 {
LINE_END,
"LINE_END", 0,
"Line End",
""},
372 {
PREV_CHAR,
"PREVIOUS_CHARACTER", 0,
"Previous Character",
""},
373 {
NEXT_CHAR,
"NEXT_CHARACTER", 0,
"Next Character",
""},
374 {
PREV_WORD,
"PREVIOUS_WORD", 0,
"Previous Word",
""},
375 {
NEXT_WORD,
"NEXT_WORD", 0,
"Next Word",
""},
376 {0,
nullptr, 0,
nullptr,
nullptr},
390 const int old_pos = ci->
cursor;
447 if (select_side != 0) {
449 if (select_side == -1) {
452 else if (select_side == 1) {
467 else if (old_pos <
pos) {
486 ot->name =
"Move Cursor";
487 ot->description =
"Move cursor position";
488 ot->idname =
"CONSOLE_OT_move";
498 ot->srna,
"select",
false,
"Select",
"Whether to select while moving");
512 while (
len > 0 &&
str[
len - 1] ==
'\n') {
517 if (strchr(
str,
'\n')) {
572 ot->description =
"Insert text at cursor position";
573 ot->idname =
"CONSOLE_OT_insert";
582 ot->srna,
"text",
nullptr, 0,
"Text",
"Text to insert at the cursor position");
593 bool text_before_cursor =
false;
600 text_before_cursor =
true;
605 if (text_before_cursor) {
619 ot->name =
"Indent or Autocomplete";
620 ot->idname =
"CONSOLE_OT_indent_or_autocomplete";
621 ot->description =
"Indent selected text or autocomplete";
647 for (spaces = 0; spaces < ci->
len; spaces++) {
648 if (ci->
line[spaces] !=
' ') {
676 ot->description =
"Add 4 spaces at line beginning";
677 ot->idname =
"CONSOLE_OT_indent";
696 for (spaces = 0; spaces < ci->
len; spaces++) {
697 if (ci->
line[spaces] !=
' ') {
731 ot->name =
"Unindent";
732 ot->description =
"Delete 4 spaces from line beginning";
733 ot->idname =
"CONSOLE_OT_unindent";
742 {
DEL_PREV_CHAR,
"PREVIOUS_CHARACTER", 0,
"Previous Character",
""},
745 {0,
nullptr, 0,
nullptr,
nullptr},
837 ot->description =
"Delete text by cursor position";
838 ot->idname =
"CONSOLE_OT_delete";
850 "Which part of the text to delete");
880 ot->name =
"Clear Line";
881 ot->description =
"Clear the line and store in history";
882 ot->idname =
"CONSOLE_OT_clear_line";
923 ot->name =
"Clear All";
924 ot->description =
"Clear text by type";
925 ot->idname =
"CONSOLE_OT_clear";
932 RNA_def_boolean(
ot->srna,
"scrollback",
true,
"Scrollback",
"Clear the scrollback history");
933 RNA_def_boolean(
ot->srna,
"history",
false,
"History",
"Clear the command history");
946 int prev_len = ci->
len;
951 if (old_index <= 0) {
955 new_index = old_index + 1;
959 if (old_index <= 0) {
960 new_index = -old_index;
963 new_index = old_index - 1;
972 ci_prev = ci_prev->
prev;
978 for (
int i = 0;
i < new_index;
i++) {
979 if (!ci_prev->
prev) {
983 ci_prev = ci_prev->
prev;
1010 ot->name =
"History Cycle";
1011 ot->description =
"Cycle through history";
1012 ot->idname =
"CONSOLE_OT_history_cycle";
1019 RNA_def_boolean(
ot->srna,
"reverse",
false,
"Reverse",
"Reverse cycle history");
1034 int prev_len = ci->
len;
1072 ot->name =
"History Append";
1073 ot->description =
"Append history at cursor position";
1074 ot->idname =
"CONSOLE_OT_history_append";
1081 RNA_def_string(
ot->srna,
"text",
nullptr, 0,
"Text",
"Text to insert at the cursor position");
1083 ot->srna,
"current_character", 0, 0, INT_MAX,
"Cursor",
"The index of the cursor", 0, 10000);
1085 "remove_duplicates",
1087 "Remove Duplicates",
1088 "Remove duplicate items in the history");
1124 {0,
nullptr, 0,
nullptr,
nullptr},
1128 ot->name =
"Scrollback Append";
1129 ot->description =
"Append scrollback text by type";
1130 ot->idname =
"CONSOLE_OT_scrollback_append";
1137 RNA_def_string(
ot->srna,
"text",
nullptr, 0,
"Text",
"Text to insert at the cursor position");
1140 console_line_type_items,
1143 "Console output type");
1150 if (buf ==
nullptr) {
1174 ot->name =
"Copy to Clipboard";
1175 ot->description =
"Copy selected text to clipboard";
1176 ot->idname =
"CONSOLE_OT_copy";
1187 "Whether to delete the selection after copying");
1202 if (buf_str ==
nullptr) {
1205 if (*buf_str ==
'\0') {
1209 const char *buf_step = buf_str;
1211 const char *buf = buf_step;
1213 const int buf_len = buf_step - buf;
1214 if (buf != buf_str) {
1222 }
while (*buf_step ? ((
void)buf_step++,
true) :
false);
1237 ot->name =
"Paste from Clipboard";
1238 ot->description =
"Paste text from clipboard";
1239 ot->idname =
"CONSOLE_OT_paste";
1251 "Paste text selected elsewhere rather than copied (X11/Wayland only)");
1266 bool dragging =
event->type ==
MOUSEMOVE;
1289 if (cl !=
nullptr) {
1341 if (cl !=
nullptr) {
1367 switch (event->
type) {
1401 ot->name =
"Set Selection";
1402 ot->idname =
"CONSOLE_OT_select_set";
1403 ot->description =
"Set the console selection";
1419 int offset = strlen(sc->
prompt);
1422 offset += cl->
len + 1;
1427 offset += cl->
len + 1;
1441 ot->name =
"Select All";
1442 ot->idname =
"CONSOLE_OT_select_all";
1443 ot->description =
"Select all the text";
1468 int sel[2] = {n, n};
1472 sel[0] = offset - sel[0];
1473 sel[1] = offset - sel[1];
1500 ot->name =
"Select Word";
1501 ot->description =
"Select word at cursor position";
1502 ot->idname =
"CONSOLE_OT_select_word";
SpaceConsole * CTX_wm_space_console(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
void BKE_report(ReportList *reports, eReportType type, const char *message)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
A dynamically sized string ADT.
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char char size_t char const char * BLI_strchr_or_end(const char *str, char ch) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
void BLI_str_cursor_step_utf8(const char *str, int str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, bool use_init_step)
void BLI_str_cursor_step_bounds_utf8(const char *str, int str_maxlen, int pos, int *r_start, int *r_end)
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void ED_area_tag_redraw(ScrArea *area)
bool ED_operator_console_active(bContext *C)
Read Guarded memory(de)allocation.
void UI_view2d_totRect_set(View2D *v2d, int width, int height)
@ WM_CAPABILITY_CLIPBOARD_PRIMARY
void console_scrollback_prompt_end(SpaceConsole *sc, ConsoleLine *cl_dummy)
int console_textview_height(SpaceConsole *sc, const ARegion *region)
void console_scrollback_prompt_begin(SpaceConsole *sc, ConsoleLine *cl_dummy)
int console_char_pick(SpaceConsole *sc, const ARegion *region, const int mval[2])
static bool console_line_cursor_set(ConsoleLine *cl, int cursor)
void CONSOLE_OT_select_all(wmOperatorType *ot)
static ConsoleLine * console_history_add(SpaceConsole *sc, ConsoleLine *from)
static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event)
static void console_select_update_primary_clipboard(SpaceConsole *sc)
static void console_line_verify_length(ConsoleLine *ci, int len)
static wmOperatorStatus console_selectword_invoke(bContext *C, wmOperator *, const wmEvent *event)
static wmOperatorStatus console_scrollback_append_exec(bContext *C, wmOperator *op)
static void console_select_set_cancel(bContext *C, wmOperator *op)
static wmOperatorStatus console_select_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus console_insert_exec(bContext *C, wmOperator *op)
void CONSOLE_OT_copy(wmOperatorType *ot)
void CONSOLE_OT_clear(wmOperatorType *ot)
static wmOperatorStatus console_modal_select_all_invoke(bContext *C, wmOperator *, const wmEvent *)
static wmOperatorStatus console_clear_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem console_move_type_items[]
static const EnumPropertyItem console_delete_type_items[]
static wmOperatorStatus console_history_append_exec(bContext *C, wmOperator *op)
static bool console_line_column_from_index(SpaceConsole *sc, const int pos, ConsoleLine **r_cl, int *r_cl_offset, int *r_col)
static wmOperatorStatus console_paste_exec(bContext *C, wmOperator *op)
void console_textview_update_rect(SpaceConsole *sc, ARegion *region)
static wmOperatorStatus console_unindent_exec(bContext *C, wmOperator *)
static void console_cursor_set_exit(bContext *C, wmOperator *op)
void CONSOLE_OT_select_word(wmOperatorType *ot)
void CONSOLE_OT_delete(wmOperatorType *ot)
static char * console_select_to_buffer(SpaceConsole *sc)
void CONSOLE_OT_indent(wmOperatorType *ot)
void CONSOLE_OT_select_set(wmOperatorType *ot)
static void console_scrollback_limit(SpaceConsole *sc)
void CONSOLE_OT_indent_or_autocomplete(wmOperatorType *ot)
void CONSOLE_OT_move(wmOperatorType *ot)
static wmOperatorStatus console_copy_exec(bContext *C, wmOperator *op)
static void console_scroll_bottom(ARegion *region)
void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
void console_scrollback_free(SpaceConsole *sc, ConsoleLine *cl)
void CONSOLE_OT_clear_line(wmOperatorType *ot)
void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
void CONSOLE_OT_insert(wmOperatorType *ot)
static ConsoleLine * console_lb_add__internal(ListBase *lb, ConsoleLine *from)
static wmOperatorStatus console_history_cycle_exec(bContext *C, wmOperator *op)
ConsoleLine * console_history_add_str(SpaceConsole *sc, char *str, bool own)
static void console_line_insert(ConsoleLine *ci, const char *str, int len)
static ConsoleLine * console_lb_add_str__internal(ListBase *lb, char *str, bool own)
static bool console_copy_poll(bContext *C)
void CONSOLE_OT_history_cycle(wmOperatorType *ot)
void CONSOLE_OT_unindent(wmOperatorType *ot)
void CONSOLE_OT_history_append(wmOperatorType *ot)
static wmOperatorStatus console_select_set_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int console_delete_editable_selection(SpaceConsole *sc)
static wmOperatorStatus console_indent_exec(bContext *C, wmOperator *)
static wmOperatorStatus console_clear_line_exec(bContext *C, wmOperator *)
void CONSOLE_OT_paste(wmOperatorType *ot)
static wmOperatorStatus console_indent_or_autocomplete_exec(bContext *C, wmOperator *)
static wmOperatorStatus console_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ConsoleLine * console_history_verify(const bContext *C)
static void console_cursor_set_to_pos(SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const wmEvent *event)
static wmOperatorStatus console_move_exec(bContext *C, wmOperator *op)
static void console_select_offset(SpaceConsole *sc, const int offset)
static wmOperatorStatus console_delete_exec(bContext *C, wmOperator *op)
ConsoleLine * console_scrollback_add_str(SpaceConsole *sc, char *str, bool own)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void *(* MEM_recallocN_id)(void *vmemh, size_t len, const char *str)
void MEM_freeN(void *vmemh)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
int RNA_int_get(PointerRNA *ptr, const char *name)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
int RNA_string_length(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
struct ConsoleLine * next
struct ConsoleLine * prev
wmEventModifierFlag modifier
struct ReportList * reports
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, blender::wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
void WM_clipboard_text_set(const char *buf, bool selection)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
eWM_CapabilitiesFlag WM_capabilities_flag()