Opening git commit works properly now
This commit is contained in:
@@ -1106,6 +1106,18 @@ struct Scratch {
|
||||
Scratch(Scratch &arena, Scratch &a2);
|
||||
};
|
||||
|
||||
struct RandomSeed {
|
||||
uint64_t a;
|
||||
};
|
||||
|
||||
inline uint64_t GetRandomU64(RandomSeed *state) {
|
||||
uint64_t x = state->a;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 7;
|
||||
x ^= x << 17;
|
||||
return state->a = x;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation
|
||||
//
|
||||
|
||||
@@ -40,11 +40,13 @@ struct StdoutPollInfo {
|
||||
};
|
||||
|
||||
struct Process {
|
||||
bool is_valid;
|
||||
String error_message;
|
||||
int exit_code;
|
||||
bool is_valid;
|
||||
String error_message;
|
||||
int exit_code;
|
||||
char platform[6 * 8];
|
||||
|
||||
int64_t view_id; // text editor view
|
||||
char platform[6 * 8];
|
||||
bool scroll_to_end;
|
||||
};
|
||||
|
||||
Process CreateCommandLineProcess(String command_line, String working_dir);
|
||||
|
||||
@@ -28,6 +28,13 @@ String FieldString(lua_State *L, String name) {
|
||||
return result;
|
||||
}
|
||||
|
||||
RandomSeed UniqueBufferNameSeed = {13};
|
||||
String GetUniqueBufferName(Allocator allocator, String working_dir, String prepend_name) {
|
||||
uint64_t number = GetRandomU64(&UniqueBufferNameSeed);
|
||||
String buffer_name = Format(allocator, "%.*s/%.*s%llu", FmtString(working_dir), FmtString(prepend_name), number);
|
||||
return buffer_name;
|
||||
}
|
||||
|
||||
void Open(String path) {
|
||||
Scratch scratch;
|
||||
|
||||
@@ -60,15 +67,14 @@ void Open(String path) {
|
||||
} else if (FieldString(LuaState, "kind") == "exec") {
|
||||
String cmd = FieldString(LuaState, "cmd");
|
||||
String working_dir = FieldString(LuaState, "working_dir");
|
||||
String asd = "asd";
|
||||
String buffer_name = Format(scratch, "%.*s/%.*s", FmtString(working_dir), FmtString(asd));
|
||||
String buffer_name = GetUniqueBufferName(scratch, working_dir, "+CMD");
|
||||
|
||||
CheckpointBeforeGoto();
|
||||
Window *window = GetWindow(GetLastActiveWindow());
|
||||
View *view = WindowOpenBufferView(window, buffer_name);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
view->carets[0] = MakeCaret({});
|
||||
Exec(view->id, cmd, working_dir);
|
||||
Exec(view->id, false, cmd, working_dir);
|
||||
SetActiveWindow(window->id);
|
||||
} else {
|
||||
ReportWarningf("Failed to match any of ApplyRules results!");
|
||||
|
||||
@@ -173,21 +173,23 @@ View *FindViewWithBufferName(String name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String GetCurrentBufferName() {
|
||||
Window *GetCurrentWindow() {
|
||||
Window *window = GetWindow(ActiveWindow);
|
||||
if (window->is_title_bar) {
|
||||
window = GetWindow(window->title_bar_window);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
String GetCurrentBufferName() {
|
||||
Window *window = GetCurrentWindow();
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
return buffer->name;
|
||||
}
|
||||
|
||||
String GetCurrentBufferDir() {
|
||||
Window *window = GetWindow(ActiveWindow);
|
||||
if (window->is_title_bar) {
|
||||
window = GetWindow(window->title_bar_window);
|
||||
}
|
||||
Window *window = GetCurrentWindow();
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
String name = buffer->is_directory ? buffer->name : ChopLastSlash(buffer->name);
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
Array<Process> ActiveProcesses = {};
|
||||
|
||||
void Exec(ViewID view, String cmd, String working_dir) {
|
||||
Process process = CreateCommandLineProcess(cmd, working_dir);
|
||||
process.view_id = view.id;
|
||||
void Exec(ViewID view, bool scroll_to_end, String cmd, String working_dir) {
|
||||
Process process = CreateCommandLineProcess(cmd, working_dir);
|
||||
process.view_id = view.id;
|
||||
process.scroll_to_end = scroll_to_end;
|
||||
if (process.is_valid) Add(&ActiveProcesses, process);
|
||||
}
|
||||
|
||||
void Exec(ViewID view, String16 cmd16, String working_dir) {
|
||||
void Exec(ViewID view, bool scroll_to_end, String16 cmd16, String working_dir) {
|
||||
Scratch scratch;
|
||||
String cmd = ToString(scratch, cmd16);
|
||||
Exec(view, cmd, working_dir);
|
||||
Exec(view, scroll_to_end, cmd, working_dir);
|
||||
}
|
||||
|
||||
void UpdateProcesses() {
|
||||
@@ -21,7 +22,7 @@ void UpdateProcesses() {
|
||||
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, false);
|
||||
if (string.len) Command_Append(view_id, string, it.scroll_to_end);
|
||||
|
||||
bool exited = PollExitCode(&it);
|
||||
if (exited) remove_item = true;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
- kill process using command in window
|
||||
- kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433
|
||||
- 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
|
||||
- Test stdin writing code
|
||||
- Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell)
|
||||
|
||||
Reference in New Issue
Block a user