66 char *buf_str =
nullptr;
72 if (sel[0] <= cl.
len && sel[1] >= 0) {
73 int sta =
max_ii(sel[0], 0);
109 if (buf ==
nullptr) {
134 del_end = std::min(del_end, cl->
len);
136 const int len = del_end - del_start;
137 memmove(cl->
line + cl->
len - del_end, cl->
line + cl->
len - del_start, del_start);
172 MEM_delete(cl->
line);
178 MEM_delete(cl->
line);
186 for (tot = sc->
scrollback.count(); tot >
U.scrollback; tot--) {
199 else if (cursor > cl->
len) {
200 cursor_new = cl->
len;
206 if (cursor_new == cl->
cursor) {
215static void console_lb_debug__internal(ListBaseT<ConsoleLine> *lb)
219 printf(
"%d: ", lb->count());
220 for (cl = lb->first_; cl; cl = cl->next) {
221 printf(
"<%s> ", cl->line);
226static void console_history_debug(
const bContext *
C)
230 console_lb_debug__internal(&sc->history);
236 ConsoleLine *ci = MEM_new<ConsoleLine>(
"ConsoleLine Add");
261static ConsoleLine *console_scrollback_add(
const bContext *
C, ConsoleLine *from)
271 ConsoleLine *ci = MEM_new<ConsoleLine>(
"ConsoleLine Add");
272 const int str_len = strlen(
str);
313 int new_len =
len + 1;
315 int new_len = (
len + 1) * 2;
353 offset += cl->
len + 1;
362 *r_cl_offset = offset;
363 *r_col = offset - pos;
377 {
LINE_BEGIN,
"LINE_BEGIN", 0,
"Line Begin",
""},
378 {
LINE_END,
"LINE_END", 0,
"Line End",
""},
379 {
PREV_CHAR,
"PREVIOUS_CHARACTER", 0,
"Previous Character",
""},
380 {
NEXT_CHAR,
"NEXT_CHARACTER", 0,
"Next Character",
""},
381 {
PREV_WORD,
"PREVIOUS_WORD", 0,
"Previous Word",
""},
382 {
NEXT_WORD,
"NEXT_WORD", 0,
"Next Word",
""},
383 {0,
nullptr, 0,
nullptr,
nullptr},
397 const int old_pos = ci->
cursor;
454 if (select_side != 0) {
456 if (select_side == -1) {
459 else if (select_side == 1) {
474 else if (old_pos < pos) {
493 ot->
name =
"Move Cursor";
495 ot->
idname =
"CONSOLE_OT_move";
505 ot->
srna,
"select",
false,
"Select",
"Whether to select while moving");
519 while (
len > 0 &&
str[
len - 1] ==
'\n') {
524 if (strchr(
str,
'\n')) {
554 if (
const std::optional<wmOperatorStatus> status = WM_operator_IME_insert_maybe(
555 C, op, event,
"text"))
587 ot->
description =
"Insert text at cursor position";
588 ot->
idname =
"CONSOLE_OT_insert";
597 ot->
srna,
"text",
nullptr, 0,
"Text",
"Text to insert at the cursor position");
608 bool text_before_cursor =
false;
614 if (!
ELEM(ci->
line[i],
' ',
'\t')) {
615 text_before_cursor =
true;
620 if (text_before_cursor) {
634 ot->
name =
"Indent or Autocomplete";
635 ot->
idname =
"CONSOLE_OT_indent_or_autocomplete";
636 ot->
description =
"Indent selected text or autocomplete";
662 for (spaces = 0; spaces < ci->
len; spaces++) {
663 if (ci->
line[spaces] !=
' ') {
691 ot->
description =
"Add 4 spaces at line beginning";
692 ot->
idname =
"CONSOLE_OT_indent";
711 for (spaces = 0; spaces < ci->
len; spaces++) {
712 if (ci->
line[spaces] !=
' ') {
746 ot->
name =
"Unindent";
747 ot->
description =
"Delete 4 spaces from line beginning";
748 ot->
idname =
"CONSOLE_OT_unindent";
757 {
DEL_PREV_CHAR,
"PREVIOUS_CHARACTER", 0,
"Previous Character",
""},
760 {0,
nullptr, 0,
nullptr,
nullptr},
766 if (
const std::optional<wmOperatorStatus> status = WM_operator_IME_edit_maybe(
C)) {
805 stride = pos - ci->
cursor;
826 stride = ci->
cursor - pos;
858 ot->
description =
"Delete text by cursor position";
859 ot->
idname =
"CONSOLE_OT_delete";
871 "Which part of the text to delete");
901 ot->
name =
"Clear Line";
902 ot->
description =
"Clear the line and store in history";
903 ot->
idname =
"CONSOLE_OT_clear_line";
944 ot->
name =
"Clear All";
946 ot->
idname =
"CONSOLE_OT_clear";
953 RNA_def_boolean(ot->
srna,
"scrollback",
true,
"Scrollback",
"Clear the scrollback history");
967 int prev_len = ci->
len;
972 if (old_index <= 0) {
976 new_index = old_index + 1;
980 if (old_index <= 0) {
981 new_index = -old_index;
984 new_index = old_index - 1;
993 ci_prev = ci_prev->
prev;
999 for (
int i = 0; i < new_index; i++) {
1000 if (!ci_prev->
prev) {
1004 ci_prev = ci_prev->
prev;
1009 if (old_index > 0) {
1013 if (new_index > 0) {
1031 ot->
name =
"History Cycle";
1033 ot->
idname =
"CONSOLE_OT_history_cycle";
1055 int prev_len = ci->
len;
1093 ot->
name =
"History Append";
1094 ot->
description =
"Append history at cursor position";
1095 ot->
idname =
"CONSOLE_OT_history_append";
1102 RNA_def_string(ot->
srna,
"text",
nullptr, 0,
"Text",
"Text to insert at the cursor position");
1104 ot->
srna,
"current_character", 0, 0,
INT_MAX,
"Cursor",
"The index of the cursor", 0, 10000);
1106 "remove_duplicates",
1108 "Remove Duplicates",
1109 "Remove duplicate items in the history");
1145 {0,
nullptr, 0,
nullptr,
nullptr},
1149 ot->
name =
"Scrollback Append";
1150 ot->
description =
"Append scrollback text by type";
1151 ot->
idname =
"CONSOLE_OT_scrollback_append";
1158 RNA_def_string(ot->
srna,
"text",
nullptr, 0,
"Text",
"Text to insert at the cursor position");
1161 console_line_type_items,
1164 "Console output type");
1171 if (buf ==
nullptr) {
1195 ot->
name =
"Copy to Clipboard";
1196 ot->
description =
"Copy selected text to clipboard";
1197 ot->
idname =
"CONSOLE_OT_copy";
1208 "Whether to delete the selection after copying");
1222 if (buf_str ==
nullptr) {
1225 if (*buf_str ==
'\0') {
1226 MEM_delete(buf_str);
1229 bool context_valid =
true;
1230 const char *buf_step = buf_str;
1232 const char *buf = buf_step;
1234 const int buf_len = buf_step - buf;
1235 if (buf != buf_str) {
1243 context_valid =
false;
1251 }
while (*buf_step ? ((
void)buf_step++,
true) :
false);
1253 MEM_delete(buf_str);
1255 if (context_valid) {
1265 "Context changed during paste, "
1266 "console execution may be incomplete");
1275 ot->
name =
"Paste from Clipboard";
1277 ot->
idname =
"CONSOLE_OT_paste";
1289 "Paste text selected elsewhere rather than copied (X11/Wayland only)");
1304 bool dragging =
event->type ==
MOUSEMOVE;
1312 if (pos < scu->sel_init) {
1327 if (cl !=
nullptr) {
1331 else if (pos <= cl->
len) {
1379 if (cl !=
nullptr) {
1381 if (pos >= 0 && pos <= cl->
len) {
1405 switch (event->
type) {
1439 ot->
name =
"Set Selection";
1440 ot->
idname =
"CONSOLE_OT_select_set";
1457 int offset = strlen(sc->
prompt);
1460 offset += cl.
len + 1;
1465 offset += cl->
len + 1;
1479 ot->
name =
"Select All";
1480 ot->
idname =
"CONSOLE_OT_select_all";
1506 int sel[2] = {n, n};
1510 sel[0] = offset - sel[0];
1511 sel[1] = offset - sel[1];
1538 ot->
name =
"Select Word";
1539 ot->
description =
"Select word at cursor position";
1540 ot->
idname =
"CONSOLE_OT_select_word";
A dynamically sized string ADT.
Read Blender memory allocation and freeing.
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
void view2d_totRect_set(View2D *v2d, int width, int height)
void CONSOLE_OT_history_cycle(wmOperatorType *ot)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void console_cursor_set_exit(bContext *C, wmOperator *op)
static wmOperatorStatus console_indent_exec(bContext *C, wmOperator *)
ScrArea * CTX_wm_area(const bContext *C)
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)
static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event)
static void console_line_verify_length(ConsoleLine *ci, int len)
void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) ATTR_NONNULL()
void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
SpaceConsole * CTX_wm_space_console(const bContext *C)
static wmOperatorStatus console_clear_exec(bContext *C, wmOperator *op)
void CONSOLE_OT_paste(wmOperatorType *ot)
static const EnumPropertyItem console_move_type_items[]
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void CONSOLE_OT_select_set(wmOperatorType *ot)
static wmOperatorStatus console_modal_select_all_invoke(bContext *C, wmOperator *, const wmEvent *)
static void console_select_set_cancel(bContext *C, wmOperator *op)
static wmOperatorStatus console_select_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void CONSOLE_OT_select_all(wmOperatorType *ot)
ConsoleLine * console_history_verify(const bContext *C)
int RNA_int_get(PointerRNA *ptr, const char *name)
ConsoleLine * console_scrollback_add_str(SpaceConsole *sc, char *str, bool own)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int max_ii(int a, int b)
void CONSOLE_OT_select_word(wmOperatorType *ot)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
void CONSOLE_OT_copy(wmOperatorType *ot)
static wmOperatorStatus console_history_append_exec(bContext *C, wmOperator *op)
static char * console_select_to_buffer(SpaceConsole *sc)
static wmOperatorStatus console_paste_exec(bContext *C, wmOperator *op)
static wmOperatorStatus console_unindent_exec(bContext *C, wmOperator *)
static void console_scrollback_limit(SpaceConsole *sc)
void CONSOLE_OT_unindent(wmOperatorType *ot)
void CONSOLE_OT_clear_line(wmOperatorType *ot)
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static wmOperatorStatus console_delete_exec(bContext *C, wmOperator *op)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BKE_report(ReportList *reports, eReportType type, const char *message)
static wmOperatorStatus console_select_set_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool ED_operator_console_active(bContext *C)
void CONSOLE_OT_history_append(wmOperatorType *ot)
static void console_select_update_primary_clipboard(SpaceConsole *sc)
void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
static bool console_line_column_from_index(SpaceConsole *sc, const int pos, ConsoleLine **r_cl, int *r_cl_offset, int *r_col)
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void CONSOLE_OT_indent(wmOperatorType *ot)
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
void console_textview_update_rect(SpaceConsole *sc, ARegion *region)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus console_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void console_scroll_bottom(ARegion *region)
int RNA_string_length(PointerRNA *ptr, const char *name)
void CONSOLE_OT_clear(wmOperatorType *ot)
static void console_line_insert(ConsoleLine *ci, const char *str, int len)
static wmOperatorStatus console_copy_exec(bContext *C, wmOperator *op)
void CONSOLE_OT_indent_or_autocomplete(wmOperatorType *ot)
@ WM_CAPABILITY_CLIPBOARD_PRIMARY
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
static ConsoleLine * console_lb_add__internal(ListBaseT< ConsoleLine > *lb, ConsoleLine *from)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static void console_select_offset(SpaceConsole *sc, const int offset)
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)
static bool console_copy_poll(bContext *C)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
static wmOperatorStatus console_history_cycle_exec(bContext *C, wmOperator *op)
static ConsoleLine * console_lb_add_str__internal(ListBaseT< ConsoleLine > *lb, char *str, bool own)
void BLI_str_cursor_step_utf8(const char *str, int str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, bool use_init_step)
eWM_CapabilitiesFlag WM_capabilities_flag()
void CONSOLE_OT_move(wmOperatorType *ot)
void WM_clipboard_text_set(const char *buf, bool selection)
static wmOperatorStatus console_move_exec(bContext *C, wmOperator *op)
void CONSOLE_OT_insert(wmOperatorType *ot)
static wmOperatorStatus console_scrollback_append_exec(bContext *C, wmOperator *op)
int console_textview_height(SpaceConsole *sc, const ARegion *region)
static bool console_line_cursor_set(ConsoleLine *cl, int cursor)
static wmOperatorStatus console_insert_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem console_delete_type_items[]
static wmOperatorStatus console_indent_or_autocomplete_exec(bContext *C, wmOperator *)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void console_scrollback_free(SpaceConsole *sc, ConsoleLine *cl)
int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void *(*) MEM_realloc_zeroed_id(void *vmemh, size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
MINLINE int min_ii(int a, int b)
void console_scrollback_prompt_end(SpaceConsole *sc, ConsoleLine *cl_dummy)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
ConsoleLine * console_history_add_str(SpaceConsole *sc, char *str, bool own)
static void console_cursor_set_to_pos(SpaceConsole *sc, ARegion *region, SetConsoleCursor *scu, const wmEvent *event)
static wmOperatorStatus console_selectword_invoke(bContext *C, wmOperator *, const wmEvent *event)
void console_scrollback_prompt_begin(SpaceConsole *sc, ConsoleLine *cl_dummy)
static int console_delete_editable_selection(SpaceConsole *sc)
void CONSOLE_OT_delete(wmOperatorType *ot)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static ConsoleLine * console_history_add(SpaceConsole *sc, ConsoleLine *from)
int console_char_pick(SpaceConsole *sc, const ARegion *region, const int mval[2])
void ED_area_tag_redraw(ScrArea *area)
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_bounds_utf8(const char *str, int str_maxlen, int pos, int *r_start, int *r_end)
static wmOperatorStatus console_clear_line_exec(bContext *C, wmOperator *)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct ConsoleLine * prev
ListBaseT< ConsoleLine > scrollback
ListBaseT< ConsoleLine > history
wmEventModifierFlag modifier
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) cancel(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports