Command_Append
This commit is contained in:
@@ -40,10 +40,11 @@ struct StdoutPollInfo {
|
||||
};
|
||||
|
||||
struct Process {
|
||||
bool is_valid;
|
||||
String error_message;
|
||||
int exit_code;
|
||||
char platform[6 * 8];
|
||||
bool is_valid;
|
||||
String error_message;
|
||||
int exit_code;
|
||||
int64_t view_id; // text editor view
|
||||
char platform[6 * 8];
|
||||
};
|
||||
|
||||
Process CreateCommandLineProcess(String command_line, String working_dir);
|
||||
|
||||
@@ -456,20 +456,9 @@ View *FindView(BufferID buffer_id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void AppendToConsole(String16 string) {
|
||||
Buffer *buffer = GetBuffer(ConsoleBufferID);
|
||||
|
||||
// @todo: ?
|
||||
View *view = FindView(buffer->id);
|
||||
Assert(view);
|
||||
|
||||
// @todo: this prevents scrolling to end. what do we do with this? I want to adjust the
|
||||
// cursor etc.
|
||||
// Array<Caret> caret_copy = Copy(GetSystemAllocator(), view->carets);
|
||||
// defer {
|
||||
// Dealloc(&view->carets);
|
||||
// view->carets = caret_copy;
|
||||
// };
|
||||
void Command_Append(ViewID view_id, String16 string) {
|
||||
View *view = GetView(view_id);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
|
||||
bool scroll_to_end = false;
|
||||
if (view) {
|
||||
@@ -477,6 +466,15 @@ void AppendToConsole(String16 string) {
|
||||
if (line == buffer->line_starts.len - 1) scroll_to_end = true;
|
||||
}
|
||||
|
||||
Array<Caret> caret_copy = {};
|
||||
if (!scroll_to_end) caret_copy = Copy(GetSystemAllocator(), view->carets);
|
||||
defer {
|
||||
if (!scroll_to_end) {
|
||||
Dealloc(&view->carets);
|
||||
view->carets = caret_copy;
|
||||
}
|
||||
};
|
||||
|
||||
Command_SelectRangeOneCursor(view, GetEndAsRange(*buffer));
|
||||
Command_Replace(view, string);
|
||||
Command_Replace(view, L"\n");
|
||||
@@ -486,30 +484,30 @@ void AppendToConsole(String16 string) {
|
||||
}
|
||||
}
|
||||
|
||||
void AppendToConsole(String string) {
|
||||
void Command_Append(ViewID view_id, String string) {
|
||||
Scratch scratch;
|
||||
String16 string16 = ToString16(scratch, string);
|
||||
AppendToConsole(string16);
|
||||
Command_Append(view_id, string16);
|
||||
}
|
||||
|
||||
void ReportErrorf(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
|
||||
AppendToConsole(string);
|
||||
Command_Append(ConsoleViewID, string);
|
||||
}
|
||||
|
||||
void ReportConsolef(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
AppendToConsole(string);
|
||||
Command_Append(ConsoleViewID, string);
|
||||
}
|
||||
|
||||
void ReportWarningf(const char *fmt, ...) {
|
||||
Scratch scratch;
|
||||
STRING_FORMAT(scratch, fmt, string);
|
||||
String16 string16 = ToString16(scratch, string);
|
||||
AppendToConsole(string16);
|
||||
Command_Append(ConsoleViewID, string16);
|
||||
SetVisibility(ConsoleWindowID, true);
|
||||
SetActiveWindow(ConsoleWindowID);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ int LuaPrint(lua_State *L) {
|
||||
Scratch scratch;
|
||||
String string = luaL_checkstring(L, 1);
|
||||
lua_pop(L, 1);
|
||||
AppendToConsole(string);
|
||||
Command_Append(ConsoleViewID, string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ WindowID PopupWindowID;
|
||||
WindowID DebugWindowID;
|
||||
WindowID ConsoleWindowID;
|
||||
|
||||
BufferID ConsoleBufferID;
|
||||
ViewID ConsoleViewID;
|
||||
BufferID DebugBufferID;
|
||||
BufferID SearchBufferID;
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
Array<Process> ActiveProcesses = {};
|
||||
|
||||
void Exec(String cmd, String working_dir) {
|
||||
void Exec(ViewID view, String cmd, String working_dir) {
|
||||
Process process = CreateCommandLineProcess(cmd, working_dir);
|
||||
process.view_id = view.id;
|
||||
if (process.is_valid) Add(&ActiveProcesses, process);
|
||||
}
|
||||
|
||||
void Exec(String16 cmd16, String working_dir) {
|
||||
void Exec(ViewID view, String16 cmd16, String working_dir) {
|
||||
Scratch scratch;
|
||||
String cmd = ToString(scratch, cmd16);
|
||||
Exec(cmd, working_dir);
|
||||
Exec(view, cmd, working_dir);
|
||||
}
|
||||
|
||||
void UpdateProcesses() {
|
||||
@@ -17,9 +18,10 @@ void UpdateProcesses() {
|
||||
char *buffer = AllocArray(scratch, char, buffer_size);
|
||||
IterRemove(ActiveProcesses) {
|
||||
IterRemovePrepare(ActiveProcesses);
|
||||
StdoutPollInfo info = PollStdout(&it, buffer, buffer_size);
|
||||
String string = {buffer, info.size_read};
|
||||
if (string.len) AppendToConsole(string);
|
||||
StdoutPollInfo info = PollStdout(&it, buffer, buffer_size);
|
||||
String string = {buffer, info.size_read};
|
||||
ViewID view_id = {it.view_id};
|
||||
if (string.len) Command_Append(view_id, string);
|
||||
|
||||
bool exited = PollExitCode(&it);
|
||||
if (exited) remove_item = true;
|
||||
|
||||
@@ -124,7 +124,8 @@ void UpdateScroll(Window *window, bool update_caret_scrolling);
|
||||
void Command_SelectEntireBuffer(View *view);
|
||||
void Command_Replace(View *view, String16 string);
|
||||
void Command_SelectRangeOneCursor(View *view, Range range);
|
||||
void Command_Append(ViewID view_id, String16 string);
|
||||
void Command_Append(ViewID view_id, String string);
|
||||
|
||||
void AppendToConsole(String string);
|
||||
void ReportErrorf(const char *fmt, ...);
|
||||
void ReportWarningf(const char *fmt, ...);
|
||||
@@ -1,6 +1,6 @@
|
||||
- I guess it's pretty dangerous passing pointers everywhere?
|
||||
- Attach BufferID to process, append to that buffer
|
||||
- kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433
|
||||
- AppendToConsole should scroll only if caret is at end and one caret otherwise the carets should not change
|
||||
- if exec is prepended with '!' symbol then run a shell command
|
||||
- Open git commit as part of "Open" in new buffer using git --no-pager show <hash>
|
||||
- try using git grep for search for now, combine with fuzzy search buffer
|
||||
|
||||
@@ -153,11 +153,11 @@ void InitWindows() {
|
||||
window->absolute_position = true;
|
||||
window->dont_save_in_active_window_history = true;
|
||||
|
||||
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("*console*"));
|
||||
ConsoleBufferID = buffer->id;
|
||||
Buffer *buffer = CreateBuffer(sys_allocator, BuffCWD("*console*"));
|
||||
// buffer->no_history = true;
|
||||
|
||||
View *view = CreateView(buffer->id);
|
||||
ConsoleViewID = view->id;
|
||||
window->active_view = view->id;
|
||||
|
||||
CreateTitlebar(window_id);
|
||||
|
||||
Reference in New Issue
Block a user