Editor FINISHED
saving works
This commit is contained in:
parent
1ee0d2b459
commit
b08c1651e6
@ -1,6 +1,8 @@
|
|||||||
#ifndef EDITOR_HPP
|
#ifndef EDITOR_HPP
|
||||||
#define EDITOR_HPP
|
#define EDITOR_HPP
|
||||||
|
|
||||||
int edit_file(const char *s);
|
// buffer must me deleted
|
||||||
|
// null there we no changes to save
|
||||||
|
char *edit_file(const char *s, int &out_len);
|
||||||
|
|
||||||
#endif // EDITOR_HPP
|
#endif // EDITOR_HPP
|
@ -374,9 +374,19 @@ void arg_editor(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *
|
|||||||
}
|
}
|
||||||
|
|
||||||
LoginInfoPointer lip = get_logininfo_pointer_from_buffer(decrypted_buffer, pass);
|
LoginInfoPointer lip = get_logininfo_pointer_from_buffer(decrypted_buffer, pass);
|
||||||
edit_file(lip.password);
|
int len = 0;
|
||||||
|
char *new_buff = edit_file(lip.password, len);
|
||||||
|
if (new_buff == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// delete_logininfo_from_buffer(decrypted_buffer, pass);
|
std::string lable = lip.label;
|
||||||
// Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
std::string username = lip.username;
|
||||||
// encrypted_buffer.save_to_file();
|
|
||||||
|
delete_logininfo_from_buffer(decrypted_buffer, pass);
|
||||||
|
add_logininfo_to_buffer(decrypted_buffer, lable.c_str(), lable.size(), username.c_str(), username.size(), new_buff, len);
|
||||||
|
|
||||||
|
Aes256::encrypt(key, decrypted_buffer, encrypted_buffer);
|
||||||
|
encrypted_buffer.save_to_file();
|
||||||
}
|
}
|
@ -372,7 +372,21 @@ char *editorRowsToString(int *buflen)
|
|||||||
*p = '\n';
|
*p = '\n';
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
|
||||||
|
if (E.numrows == 1)
|
||||||
|
{
|
||||||
|
totlen--;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < totlen; i++)
|
||||||
|
{
|
||||||
|
if (buf[i] != '\n' && buf[i] != '\t' && iscntrl(buf[i]))
|
||||||
|
{
|
||||||
|
buf[i] = '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf[totlen - 1] = '\0';
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,8 +403,10 @@ void editorOpen(const char *data)
|
|||||||
start = end + 1;
|
start = end + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data[start] != '\0')
|
||||||
editorInsertRow(E.numrows, &data[start], end - start);
|
{
|
||||||
|
editorInsertRow(E.numrows, &data[start], end - start);
|
||||||
|
}
|
||||||
E.dirty = 0;
|
E.dirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +415,7 @@ void editorSave()
|
|||||||
// int len;
|
// int len;
|
||||||
// char *buf = editorRowsToString(&len);
|
// char *buf = editorRowsToString(&len);
|
||||||
// free(buf);
|
// free(buf);
|
||||||
// editorSetStatusMessage("Saved");
|
editorSetStatusMessage("Saved");
|
||||||
E.dirty = 0;
|
E.dirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,12 +624,11 @@ void editorDrawRows(struct abuf *ab)
|
|||||||
void editorDrawStatusBar(struct abuf *ab)
|
void editorDrawStatusBar(struct abuf *ab)
|
||||||
{
|
{
|
||||||
abAppend(ab, "\x1b[7m", 4);
|
abAppend(ab, "\x1b[7m", 4);
|
||||||
char status[80], rstatus[80];
|
char status[25], rstatus[25];
|
||||||
int len = snprintf(status, sizeof(status), "%.20s - %d lines %s",
|
|
||||||
"[No Name]", E.numrows,
|
int len = snprintf(status, sizeof(status), "%s", E.dirty ? "(will not be saved)" : "(will be saved)");
|
||||||
E.dirty ? "(modified)" : "");
|
int rlen = snprintf(rstatus, sizeof(rstatus), "%d | %d/%d", E.cx, E.cy + 1, E.numrows);
|
||||||
int rlen = snprintf(rstatus, sizeof(rstatus), "%s | %d/%d",
|
|
||||||
"no ft", E.cy + 1, E.numrows);
|
|
||||||
if (len > E.screencols)
|
if (len > E.screencols)
|
||||||
len = E.screencols;
|
len = E.screencols;
|
||||||
abAppend(ab, status, len);
|
abAppend(ab, status, len);
|
||||||
@ -894,7 +909,7 @@ void initEditor()
|
|||||||
E.screenrows -= 2;
|
E.screenrows -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int edit_file(const char *s)
|
char *edit_file(const char *s, int &out_len)
|
||||||
{
|
{
|
||||||
initEditor();
|
initEditor();
|
||||||
if (s)
|
if (s)
|
||||||
@ -911,5 +926,9 @@ int edit_file(const char *s)
|
|||||||
editorProcessKeypress();
|
editorProcessKeypress();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (E.dirty)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return editorRowsToString(&out_len);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user