Opening new buffer which is git show commit command
This commit is contained in:
@@ -312,11 +312,18 @@ function MatchAgainstIncludes(s)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MatchGitCommit(s)
|
||||||
|
local command = "git --no-pager show "..s
|
||||||
|
return {kind = "exec", cmd = command, working_dir = GetCurrentBufferDir()}
|
||||||
|
end
|
||||||
|
|
||||||
Rules = {
|
Rules = {
|
||||||
GenericTextFileRule,
|
GenericTextFileRule,
|
||||||
MatchAgainstIncludes,
|
MatchAgainstIncludes,
|
||||||
|
MatchGitCommit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function ApplyRules(s)
|
function ApplyRules(s)
|
||||||
for i = #Rules,1,-1 do
|
for i = #Rules,1,-1 do
|
||||||
rule = Rules[i]
|
rule = Rules[i]
|
||||||
|
|||||||
@@ -421,11 +421,24 @@ StdoutPollInfo PollStdout(Process *process, char *buffer, int64_t buffer_size) {
|
|||||||
Assert(process->is_valid);
|
Assert(process->is_valid);
|
||||||
Win32Process *p = (Win32Process *)process->platform;
|
Win32Process *p = (Win32Process *)process->platform;
|
||||||
|
|
||||||
DWORD bytes_read = 0;
|
|
||||||
DWORD bytes_avail = 0;
|
DWORD bytes_avail = 0;
|
||||||
|
|
||||||
bool peek_error = PeekNamedPipe(p->child_stdout_read, buffer, (DWORD)buffer_size, &bytes_read, &bytes_avail, NULL) == 0;
|
StdoutPollInfo result = {};
|
||||||
|
bool peek_error = PeekNamedPipe(p->child_stdout_read, NULL, 0, NULL, &bytes_avail, NULL) == 0;
|
||||||
|
if (peek_error) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
StdoutPollInfo result = {bytes_read, bytes_avail};
|
if (bytes_avail == 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD bytes_read = 0;
|
||||||
|
bool read_error = ReadFile(p->child_stdout_read, buffer, (DWORD)buffer_size, &bytes_read, 0) == 0;
|
||||||
|
if (read_error) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = {bytes_read, bytes_avail - bytes_read};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -456,12 +456,12 @@ View *FindView(BufferID buffer_id) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_Append(ViewID view_id, String16 string) {
|
void Command_Append(ViewID view_id, String16 string, bool scroll_to_end_if_cursor_on_last_line) {
|
||||||
View *view = GetView(view_id);
|
View *view = GetView(view_id);
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
|
||||||
bool scroll_to_end = false;
|
bool scroll_to_end = false;
|
||||||
if (view) {
|
if (scroll_to_end_if_cursor_on_last_line) {
|
||||||
Int line = PosToLine(*buffer, GetFront(view->carets[0]));
|
Int line = PosToLine(*buffer, GetFront(view->carets[0]));
|
||||||
if (line == buffer->line_starts.len - 1) scroll_to_end = true;
|
if (line == buffer->line_starts.len - 1) scroll_to_end = true;
|
||||||
}
|
}
|
||||||
@@ -484,30 +484,29 @@ void Command_Append(ViewID view_id, String16 string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_Append(ViewID view_id, String string) {
|
void Command_Append(ViewID view_id, String string, bool scroll_to_end_if_cursor_on_last_line) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String16 string16 = ToString16(scratch, string);
|
String16 string16 = ToString16(scratch, string);
|
||||||
Command_Append(view_id, string16);
|
Command_Append(view_id, string16, scroll_to_end_if_cursor_on_last_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReportErrorf(const char *fmt, ...) {
|
void ReportErrorf(const char *fmt, ...) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
|
||||||
Command_Append(ConsoleViewID, string);
|
Command_Append(ConsoleViewID, string, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReportConsolef(const char *fmt, ...) {
|
void ReportConsolef(const char *fmt, ...) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
Command_Append(ConsoleViewID, string);
|
Command_Append(ConsoleViewID, string, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReportWarningf(const char *fmt, ...) {
|
void ReportWarningf(const char *fmt, ...) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
STRING_FORMAT(scratch, fmt, string);
|
STRING_FORMAT(scratch, fmt, string);
|
||||||
String16 string16 = ToString16(scratch, string);
|
Command_Append(ConsoleViewID, string, true);
|
||||||
Command_Append(ConsoleViewID, string16);
|
|
||||||
SetVisibility(ConsoleWindowID, true);
|
SetVisibility(ConsoleWindowID, true);
|
||||||
SetActiveWindow(ConsoleWindowID);
|
SetActiveWindow(ConsoleWindowID);
|
||||||
}
|
}
|
||||||
@@ -204,11 +204,18 @@ function MatchAgainstIncludes(s)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MatchGitCommit(s)
|
||||||
|
local command = "git --no-pager show "..s
|
||||||
|
return {kind = "exec", cmd = command, working_dir = GetCurrentBufferDir()}
|
||||||
|
end
|
||||||
|
|
||||||
Rules = {
|
Rules = {
|
||||||
GenericTextFileRule,
|
GenericTextFileRule,
|
||||||
MatchAgainstIncludes,
|
MatchAgainstIncludes,
|
||||||
|
MatchGitCommit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function ApplyRules(s)
|
function ApplyRules(s)
|
||||||
for i = #Rules,1,-1 do
|
for i = #Rules,1,-1 do
|
||||||
rule = Rules[i]
|
rule = Rules[i]
|
||||||
|
|||||||
@@ -57,6 +57,19 @@ void Open(String path) {
|
|||||||
}
|
}
|
||||||
UpdateScroll(window, true);
|
UpdateScroll(window, true);
|
||||||
SetActiveWindow(window->id);
|
SetActiveWindow(window->id);
|
||||||
|
} 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));
|
||||||
|
|
||||||
|
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);
|
||||||
|
SetActiveWindow(window->id);
|
||||||
} else {
|
} else {
|
||||||
ReportWarningf("Failed to match any of ApplyRules results!");
|
ReportWarningf("Failed to match any of ApplyRules results!");
|
||||||
}
|
}
|
||||||
@@ -80,7 +93,7 @@ int LuaPrint(lua_State *L) {
|
|||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String string = luaL_checkstring(L, 1);
|
String string = luaL_checkstring(L, 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
Command_Append(ConsoleViewID, string);
|
Command_Append(ConsoleViewID, string, true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void UpdateProcesses() {
|
|||||||
StdoutPollInfo info = PollStdout(&it, buffer, buffer_size);
|
StdoutPollInfo info = PollStdout(&it, buffer, buffer_size);
|
||||||
String string = {buffer, info.size_read};
|
String string = {buffer, info.size_read};
|
||||||
ViewID view_id = {it.view_id};
|
ViewID view_id = {it.view_id};
|
||||||
if (string.len) Command_Append(view_id, string);
|
if (string.len) Command_Append(view_id, string, false);
|
||||||
|
|
||||||
bool exited = PollExitCode(&it);
|
bool exited = PollExitCode(&it);
|
||||||
if (exited) remove_item = true;
|
if (exited) remove_item = true;
|
||||||
|
|||||||
@@ -124,8 +124,8 @@ void UpdateScroll(Window *window, bool update_caret_scrolling);
|
|||||||
void Command_SelectEntireBuffer(View *view);
|
void Command_SelectEntireBuffer(View *view);
|
||||||
void Command_Replace(View *view, String16 string);
|
void Command_Replace(View *view, String16 string);
|
||||||
void Command_SelectRangeOneCursor(View *view, Range range);
|
void Command_SelectRangeOneCursor(View *view, Range range);
|
||||||
void Command_Append(ViewID view_id, String16 string);
|
void Command_Append(ViewID view_id, String16 string, bool scroll_to_end_if_cursor_on_last_line);
|
||||||
void Command_Append(ViewID view_id, String string);
|
void Command_Append(ViewID view_id, String string, bool scroll_to_end_if_cursor_on_last_line);
|
||||||
|
|
||||||
void ReportErrorf(const char *fmt, ...);
|
void ReportErrorf(const char *fmt, ...);
|
||||||
void ReportWarningf(const char *fmt, ...);
|
void ReportWarningf(const char *fmt, ...);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
- I guess it's pretty dangerous passing pointers everywhere?
|
- I guess it's pretty dangerous passing pointers everywhere?
|
||||||
- Attach BufferID to process, append to that buffer
|
- kill process using command in window
|
||||||
- kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433
|
- 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
|
- 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>
|
- Open git commit as part of "Open" in new buffer using git --no-pager show <hash>
|
||||||
|
|||||||
Reference in New Issue
Block a user