чување 084ff72a70bbc595fb1d599c098eb41bea505570
родитељ 5e5e68678295fe862cc4f84f3f5149a5f9661337
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 20 Feb 2022 21:10:05 +0100
Move format_* functions to draw.c; remove version and usage; update README
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | README | | | 8 | +++++++- |
| M | draw.c | | | 43 | +++++++++++++++++++++++++++++++++++++++++++ |
| M | sled.c | | | 77 | +++++++++-------------------------------------------------------------------- |
измењених датотека: 3, додавања: 59(+), брисања: 69(-)
diff --git a/README b/README
@@ -1,7 +1,8 @@
sled - Simple text editor
=========================
-Currently not yet functional. In the process of reusing code from poe[1].
+Currently not yet functional (getting there though!). In the process of reusing
+code from poe[1].
[1]: https://sr.ht/~strahinja/poe
@@ -34,6 +35,11 @@ A: No, and never will be. sled is intended to be configured through editing
Q: Are plugins planned?
A: No. Like suckless software, sled is meant to be extended through patches.
+Q: Why doesn't sled have feature X from text editor Y?
+A: Most likely because it is not essential to editing text files. However, you
+ are free to offer a patch supporting the feature, which will be included in
+ the repository, with credits to the author.
+
Q: How can I configure sled if I installed it (from AUR|through my distro's
package manager)?
A: You don't. If you want customization/configuration, clone the git repo,
diff --git a/draw.c b/draw.c
@@ -143,6 +143,49 @@ free_drawstate(struct DrawState* state)
free(state->input);
}
+void
+format_filename(char* result, size_t result_size, const char* format,
+ const struct DrawState* state)
+{
+ if (!result)
+ return;
+ snprintf(result, result_size, format, u8_basename(state->filename),
+ state->dirty ? "*" : "");
+}
+
+void
+format_mode(char* result, size_t result_size, const char* format,
+ const struct DrawState* state)
+{
+ const char* mode_label = mode_labels[UNKNOWN_MODE];
+ if (!result)
+ return;
+ if (state->show_help)
+ mode_label = mode_labels[HELP_MODE];
+ else if (state->in_prompt)
+ mode_label = mode_labels[PROMPT_MODE];
+ else if (state->in_selection_mode)
+ mode_label = mode_labels[SELECTION_MODE];
+ else if (state->in_command_mode)
+ mode_label = mode_labels[COMMAND_MODE];
+ else
+ mode_label = mode_labels[INSERT_MODE];
+
+ snprintf(result, result_size, format, mode_label);
+}
+
+void
+format_position(char* result, size_t result_size, const char* format,
+ const struct DrawState* state)
+{
+ if (!result)
+ return;
+ snprintf(result, result_size, format, state->column + 1, state->row + 1,
+ state->rows_count > 1
+ ? (state->row * 100) / (state->rows_count - 1)
+ : 0);
+}
+
/* Calculates display length of a buffer line.
* max_index = the buffer index up to which the length is calculated
*/
diff --git a/sled.c b/sled.c
@@ -48,14 +48,6 @@ extern const char* prompt_reread_dirty;
extern const char* program_name;
int print_error(const int code, const char* msg, ...);
-int version();
-int usage();
-void format_filename(char* result, size_t result_size, const char* format,
- const struct DrawState* state);
-void format_position(char* result, size_t result_size, const char* format,
- const struct DrawState* state);
-void format_msgs(char* result, size_t result_size, const char* format,
- const struct DrawState* state);
void reread_file(struct DrawState* state);
void reread_callback(struct DrawState* state, struct tb_event* ev);
void quit_callback(struct DrawState* state, struct tb_event* ev);
@@ -83,64 +75,6 @@ print_error(const int code, const char* msg, ...)
return code;
}
-int
-version()
-{
- printf("%s %s, built on %s\n", program_name, VERSION, DATE);
- return 0;
-}
-
-int
-usage()
-{
- printf("Usage: %s [-h|--help] [-v|--version] [filename]\n",
- program_name);
- return 0;
-}
-
-void
-format_filename(char* result, size_t result_size, const char* format,
- const struct DrawState* state)
-{
- if (!result)
- return;
- snprintf(result, result_size, format, u8_basename(state->filename),
- state->dirty ? "*" : "");
-}
-
-void
-format_mode(char* result, size_t result_size, const char* format,
- const struct DrawState* state)
-{
- const char* mode_label = mode_labels[UNKNOWN_MODE];
- if (!result)
- return;
- if (state->show_help)
- mode_label = mode_labels[HELP_MODE];
- else if (state->in_prompt)
- mode_label = mode_labels[PROMPT_MODE];
- else if (state->in_selection_mode)
- mode_label = mode_labels[SELECTION_MODE];
- else if (state->in_command_mode)
- mode_label = mode_labels[COMMAND_MODE];
- else
- mode_label = mode_labels[INSERT_MODE];
-
- snprintf(result, result_size, format, mode_label);
-}
-
-void
-format_position(char* result, size_t result_size, const char* format,
- const struct DrawState* state)
-{
- if (!result)
- return;
- snprintf(result, result_size, format, state->column + 1, state->row + 1,
- state->rows_count > 1
- ? (state->row * 100) / (state->rows_count - 1)
- : 0);
-}
-
void
reread_file(struct DrawState* state)
{
@@ -1627,9 +1561,16 @@ main(int argc, char** argv)
return print_error(1, "No filename given");
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
- return usage();
+ {
+ printf("Usage: %s [-h|--help] [-v|--version] [filename]\n",
+ program_name);
+ return 0;
+ }
else if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))
- return version();
+ {
+ printf("%s %s, built on %s\n", program_name, VERSION, DATE);
+ return 0;
+ }
else
{
strncpy(filename, argv[1], MAXPATH - 1);