This commit is contained in:
krzosa
2025-05-01 15:06:43 +02:00
parent 6374f3cd1a
commit d1d9b39200
8 changed files with 74 additions and 271 deletions

View File

@@ -161,7 +161,6 @@ void Command_Append(View *view, String16 string, bool scroll_to_end_if_cursor_on
Command_SelectRangeOneCursor(view, GetEndAsRange(buffer));
Command_Replace(view, string);
Command_Replace(view, u"\n");
if (scroll_to_end) {
view->carets[0] = MakeCaret(GetEndAsRange(buffer).min);
@@ -185,7 +184,7 @@ void ReportErrorf(const char *fmt, ...) {
STRING_FORMAT(scratch, fmt, string);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", string.data, NULL);
View *view = GetView(NullViewID);
Command_Append(view, string, true);
Command_Appendf(view, "%.*s\n", FmtString(string));
// Set console view as active
{
@@ -207,14 +206,14 @@ void ReportConsolef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
View *view = GetView(NullViewID);
Command_Append(view, string, true);
Command_Appendf(view, "%.*s\n", FmtString(string));
}
void ReportWarningf(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
View *null_view = GetView(NullViewID);
Command_Append(null_view, string, true);
Command_Appendf(null_view, "%.*s\n", FmtString(string));
// Set console view as active
{

View File

@@ -21,7 +21,11 @@ void ListFilesRecursive(Buffer *buffer, String filename) {
if (it.is_directory) {
ListFilesRecursive(buffer, it.absolute_path);
} else {
bool good = EndsWith(it.filename, ".c") || EndsWith(it.filename, ".h") || EndsWith(it.filename, ".cpp") || EndsWith(it.filename, ".hpp");
bool good = EndsWith(it.filename, ".c") ||
EndsWith(it.filename, ".h") ||
EndsWith(it.filename, ".cpp") ||
EndsWith(it.filename, ".hpp") ||
EndsWith(it.filename, ".bat");
if (!good) {
continue;
}
@@ -274,10 +278,8 @@ void OnCommand(Event event) {
}
}
if (CtrlShiftPress(SDLK_P)) {
if (CtrlPress(SDLK_P)) {
Command_ListBuffers();
} else if (CtrlPress(SDLK_P)) {
Command_GetCFiles();
}
if (CtrlShiftPress(SDLK_BACKSLASH)) {
@@ -322,8 +324,6 @@ void OnCommand(Event event) {
WindowOpenBufferView(active.window, event.text);
}
if (CtrlAltPress(SDLK_DOWN)) {
Command_DuplicateLine(active.view, DIR_DOWN);
} else if (AltShiftPress(SDLK_DOWN)) {
@@ -490,7 +490,9 @@ void OnCommand(Event event) {
Command_IdentedNewLine(active.view);
}
if (CtrlPress(SDLK_F)) {
if (CtrlShiftPress(SDLK_F)) {
// because using lua thing
} else if (CtrlPress(SDLK_F)) {
if (!active.window->is_search_bar) {
BSet search = GetBSet(main.window->search_bar_window);
String16 string = GetString(main.buffer, main.view->carets[0].range);

View File

@@ -67,7 +67,6 @@ Style.FontSize = 12
Style.FontFilter = 0
Style.Font = "C:/Windows/Fonts/consola.ttf"
Style.VCVarsall = "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat"
INTERNET_BROWSER = 'C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe'
SDLK_CTRL = 1073742048
@@ -181,13 +180,17 @@ end
function SkipDrive(s)
local i, j = s:find("^%a:")
if not i then return s, nil, true end
if not i then
return s, nil, true
end
local drive = s:sub(i, j)
local new_s = s:sub(j + 1)
new_s, found_slash = SkipSlashes(new_s)
if not found_slash then return s, drive, false end
if not found_slash then
return s, drive, false
end
return new_s, drive, true
end
@@ -209,6 +212,10 @@ function SkipPath(s)
if not ok then return s end
local cells = {}
if drive ~= nil then
table.insert(cells, drive)
end
while true do
s, word, slash_eaten = SkipPathCell(s)
if word then cells[#cells + 1] = word end
@@ -224,7 +231,14 @@ end
function MatchWindowsPath(_s)
local s, file_path, drive = SkipPath(_s)
if not file_path then return nil end
if not file_path and FileExists(drive) then
return {kind = "text", file_path = drive, line = line, col = col}
end
if not file_path then
return nil
end
if not drive then
local d = GetDir()
@@ -310,7 +324,6 @@ end
function OnInit()
end
)==";
void ReloadStyle() {
ColorText = GetColor("Text", ColorText);

View File

@@ -38,6 +38,35 @@ View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
return view;
}
// void Command_Exec(String cmd) {
// BSet main = GetActiveMainSet();
// Window *next_window = GetNextLayoutWindow(main.window);
// BSet set = GetBSet(next_window);
// CheckpointBeforeGoto(set.window);
// String working_dir = Command_GetDir();
// Exec(NullViewID, true, cmd, working_dir);
// set.window->active_view = NullViewID;
// ActiveWindow = set.window->id;
// }
void Command_Exec(String cmd, String working_dir) {
BSet main = GetActiveMainSet();
CheckpointBeforeGoto(main.window);
Buffer *buffer = GetBuffer(NullBufferID);
View *view = WindowOpenBufferView(main.window, buffer->name);
Exec(view->id, true, cmd, working_dir);
Int pos = XYToPos(buffer, {0, buffer->line_starts.len - 1});
view->carets[0] = MakeCaret(pos);
UpdateScroll(main.window, true);
main.window->active_view = view->id;
ActiveWindow = main.window->id;
}
void Command_Open(String path) {
Scratch scratch;
@@ -71,8 +100,9 @@ void Command_Open(String path) {
} else if (FieldString(LuaState, "kind") == "exec") {
String cmd = FieldString(LuaState, "cmd");
String working_dir = FieldString(LuaState, "working_dir");
Command_ExecInNewBuffer(main, cmd, working_dir);
Command_Exec(cmd, Command_GetDir());
} else if (FieldString(LuaState, "kind") == "exec_console") {
// this shouldn't change the focus/window/view
String cmd = FieldString(LuaState, "cmd");
String working_dir = FieldString(LuaState, "working_dir");
Exec(NullViewID, true, cmd, working_dir);
@@ -87,11 +117,10 @@ void Command_Open(String16 path) {
Command_Open(string);
}
int Lua_AppendCmd(lua_State *L) {
int Lua_C(lua_State *L) {
String string = lua_tostring(L, 1);
lua_pop(L, 1);
String working_dir = Command_GetDir();
Exec(NullViewID, true, string, working_dir);
Command_Exec(string, Command_GetDir());
return 0;
}
@@ -107,7 +136,7 @@ int Lua_Eval(lua_State *L) {
return 0;
}
int Lua_C(lua_State *L) {
int Lua_NewWindowCMD(lua_State *L) {
String string = lua_tostring(L, 1);
lua_pop(L, 1);
@@ -158,8 +187,9 @@ int Lua_Print(lua_State *L) {
View *null_view = GetView(NullViewID);
for (int i = 1; i <= nargs; i += 1) {
String string = lua_tostring(L, i);
Command_Append(null_view, string, true);
Command_Appendf(null_view, "%.*s ", FmtString(string));
}
Command_Appendf(null_view, "\n");
lua_pop(L, nargs);
return 0;
}
@@ -441,6 +471,7 @@ void ReloadStyle();
extern String BaseLuaConfig;
void LoadLuaBuffer(Buffer *lua_buffer) {
if (!lua_buffer) return;
ReportConsolef("reloading config: %.*s", FmtString(lua_buffer->name));
Scratch scratch;

View File

@@ -1,7 +1,7 @@
luaL_Reg LuaFunctions[] = {
{"AppendCmd", Lua_AppendCmd},
{"Eval", Lua_Eval},
{"C", Lua_C},
{"Eval", Lua_Eval},
{"NewWindowCMD", Lua_NewWindowCMD},
{"Cmd", Lua_Cmd},
{"Print", Lua_Print},
{"Kill", Lua_Kill},

View File

@@ -55,7 +55,7 @@ void KillProcess(View *view) {
if (view_id == view->id) {
KillProcess(&it);
remove_item = true;
String string = "process was killed by user";
String string = "process was killed by user\n";
Command_Append(view, string, it.scroll_to_end);
// dont break because that will fuck with removal ...
}

View File

@@ -1,3 +1,4 @@
- maybe commands should mostly be dumped into a single buffer
- When moving last line alt + arrow key it moves it into upper line, super annoying
- maybe we could allow user to change window titles which would make them special in some way. A:/text_editor/+test_buffer:1:1:ADE |
@@ -12,6 +13,7 @@ activate_buffer
- dump text editor state to file, restore state
- help menu popup when for example in process buffer, on tile bar buffer and stuff like that
- shift click inside selection should move the selection
- shift click larger then screen jumps the view to other caret
- report errors (try showing a window)
- proper lister