Ls and some improvements
This commit is contained in:
@@ -1,20 +1,6 @@
|
|||||||
lua_State *LuaState = NULL;
|
lua_State *LuaState = NULL;
|
||||||
String16 LuaCommandResult = {};
|
String16 LuaCommandResult = {};
|
||||||
|
|
||||||
String ListFiles(String path) {
|
|
||||||
Scratch scratch;
|
|
||||||
Array<String> strings = {scratch};
|
|
||||||
Add(&strings, String{"Open \"..\""});
|
|
||||||
for (FileIter iter = IterateFiles(scratch, path); IsValid(iter); Advance(&iter)) {
|
|
||||||
String string = Format(scratch, "Open \"%.*s\"", FmtString(iter.absolute_path));
|
|
||||||
Add(&strings, string);
|
|
||||||
}
|
|
||||||
Add(&strings, Format(scratch, "working dir = %.*s", FmtString(WorkingDir)));
|
|
||||||
|
|
||||||
String result = Merge(scratch, strings, "\n");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
String FieldString(lua_State *L, String name) {
|
String FieldString(lua_State *L, String name) {
|
||||||
String result = {};
|
String result = {};
|
||||||
if (lua_istable(L, -1)) {
|
if (lua_istable(L, -1)) {
|
||||||
@@ -183,13 +169,28 @@ int Lua_GetActiveMainWindowBufferDir(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Lua_OpenFilesHere(lua_State *L) {
|
void ListFilesRecursive(Buffer *buffer, String filename) {
|
||||||
|
Scratch scratch(buffer->line_starts.allocator);
|
||||||
|
for (FileIter it = IterateFiles(scratch, filename); IsValid(it); Advance(&it)) {
|
||||||
|
if (it.filename == ".git") continue;
|
||||||
|
if (it.is_directory) {
|
||||||
|
ListFilesRecursive(buffer, it.absolute_path);
|
||||||
|
} else {
|
||||||
|
IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.absolute_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Lua_Ls(lua_State *L) {
|
||||||
BSet main = GetActiveMainSet();
|
BSet main = GetActiveMainSet();
|
||||||
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
for (FileIter it = IterateFiles(scratch, GetActiveMainWindowBufferDir()); IsValid(it); Advance(&it)) {
|
String buffer_name = GetUniqueBufferName(scratch, GetDir(main.buffer), "+ls-");
|
||||||
WindowOpenBufferView(main.window, it.absolute_path);
|
|
||||||
}
|
Buffer *buffer = CreateBuffer(GetSystemAllocator(), buffer_name, 4096 * 4);
|
||||||
|
ListFilesRecursive(buffer, GetActiveMainWindowBufferDir());
|
||||||
|
WindowOpenBufferView(main.window, buffer_name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{"GetWorkingDir", Lua_GetWorkingDir},
|
{"GetWorkingDir", Lua_GetWorkingDir},
|
||||||
{"GetActiveMainWindowBufferName", Lua_GetActiveMainWindowBufferName},
|
{"GetActiveMainWindowBufferName", Lua_GetActiveMainWindowBufferName},
|
||||||
{"GetActiveMainWindowBufferDir", Lua_GetActiveMainWindowBufferDir},
|
{"GetActiveMainWindowBufferDir", Lua_GetActiveMainWindowBufferDir},
|
||||||
{"OpenFilesHere", Lua_OpenFilesHere},
|
{"Ls", Lua_Ls},
|
||||||
{"Search", Lua_Search},
|
{"Search", Lua_Search},
|
||||||
{"SearchB", Lua_SearchB},
|
{"SearchB", Lua_SearchB},
|
||||||
{"Rename", Lua_Rename},
|
{"Rename", Lua_Rename},
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); }
|
|||||||
|
|
||||||
void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 4096) {
|
void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 4096) {
|
||||||
buffer->id = AllocBufferID(buffer);
|
buffer->id = AllocBufferID(buffer);
|
||||||
buffer->name = name;
|
buffer->name = Intern(&GlobalInternTable, name);
|
||||||
buffer->cap = size;
|
buffer->cap = size;
|
||||||
buffer->data = AllocArray(allocator, U16, buffer->cap);
|
buffer->data = AllocArray(allocator, U16, buffer->cap);
|
||||||
buffer->line_starts.allocator = allocator;
|
buffer->line_starts.allocator = allocator;
|
||||||
@@ -294,10 +294,8 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!FileExists(path)) {
|
if (!FileExists(path)) {
|
||||||
path = Intern(&GlobalInternTable, path);
|
|
||||||
buffer = CreateBuffer(sys_allocator, path);
|
buffer = CreateBuffer(sys_allocator, path);
|
||||||
} else if (IsDir(path)) {
|
} else if (IsDir(path)) {
|
||||||
path = Intern(&GlobalInternTable, path);
|
|
||||||
buffer = CreateBuffer(sys_allocator, path, 4096 * 2);
|
buffer = CreateBuffer(sys_allocator, path, 4096 * 2);
|
||||||
buffer->is_directory = true;
|
buffer->is_directory = true;
|
||||||
|
|
||||||
@@ -305,7 +303,6 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.filename));
|
IKnowWhatImDoing_Appendf(buffer, "%.*s\n", FmtString(it.filename));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
path = Intern(&GlobalInternTable, path);
|
|
||||||
String string = ReadFile(scratch, path);
|
String string = ReadFile(scratch, path);
|
||||||
buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096);
|
buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096);
|
||||||
buffer->len = ConvertUTF8ToUTF16UnixLine(string, buffer->str, buffer->cap);
|
buffer->len = ConvertUTF8ToUTF16UnixLine(string, buffer->str, buffer->cap);
|
||||||
|
|||||||
Reference in New Issue
Block a user