20 Commits

Author SHA1 Message Date
15e583beb2 Bump version to 0.9 2018-11-02 21:50:36 +01:00
cdb86652b9 Fix unmarking behaviour, cleanup 2018-10-29 15:04:22 +01:00
cbdec0552d Allow moving multiple items in the Current tab 2018-10-29 14:45:25 +01:00
2cd100af7a Remove an outdated comment 2018-10-29 13:44:43 +01:00
44ebc3591e Make holding Shift+Up/Down behave better 2018-10-29 13:42:39 +01:00
0691c533b4 Update selection on playlist changes 2018-10-29 13:22:56 +01:00
6298235e22 Add actions for repeat/random/single/consume
Now the user can at least toggle them from the help tab,
or even bind them as necessary.
2018-10-29 09:58:43 +01:00
841e2f79c0 Make help tab items actionable 2018-10-29 09:46:45 +01:00
5ade0f082e Show unbound actions in help 2018-10-29 09:19:34 +01:00
0e443c0dcd Add color themes to contrib 2018-10-22 20:36:06 +02:00
a6543a796d Implement multiselect for deletion in Current tab 2018-10-21 05:11:20 +02:00
1349e39941 Add keyboard shortcut d for deletion
As in vi(1).
2018-10-21 05:10:04 +02:00
a53d24861f Update README 2018-10-21 04:27:00 +02:00
f7e4d8d3d3 Add keyboard shortcuts g/G for goto top/bottom
As in less(1).
2018-10-21 04:20:06 +02:00
8f362e787b Add a search feature for Library tab 2018-10-21 04:17:05 +02:00
609ddfab22 Cleanup 2018-10-20 22:22:26 +02:00
804f051d66 Implement sequential multiselect for Library tab 2018-10-20 22:22:26 +02:00
3c09a16a02 Fix input handling
When app_process_termo_event() returns false, it always means to beep,
not to quit the application.
2018-10-20 22:13:33 +02:00
9c16ab4136 Mark an issue for later 2018-10-20 22:13:32 +02:00
f241a7016a Move the line editor into its own file
Trying to make it reusable in other projects.
2018-10-20 22:13:32 +02:00
7 changed files with 912 additions and 377 deletions

View File

@@ -9,7 +9,7 @@ endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
# Version
set (project_VERSION_MAJOR "0")
set (project_VERSION_MINOR "1")
set (project_VERSION_MINOR "9")
set (project_VERSION_PATCH "0")
set (project_VERSION "${project_VERSION_MAJOR}")

4
NEWS Normal file
View File

@@ -0,0 +1,4 @@
0.9.0 (2018-11-02)
* Initial release

View File

@@ -11,9 +11,9 @@ names, and should be pronounced as "nincompoop".
Features
--------
Currently it's still under development but it's already useful enough for me
to use it exclusively. Note that since I only use the filesystem browsing mode,
that's also the only thing I care to implement for the time being.
Most things are there. Enough for me to use it exclusively. Note that since I
only use the filesystem browsing mode, that's also the only thing I care to
implement for the time being.
image::nncmpp.png[align="center"]
@@ -59,16 +59,17 @@ settings = {
root = "~/Music"
}
colors = {
normal = ""
highlight = "bold"
elapsed = "reverse"
remains = "ul"
tab_bar = "reverse"
tab_active = "ul"
even = ""
odd = ""
selection = "reverse"
scrollbar = ""
normal = ""
highlight = "bold"
elapsed = "reverse"
remains = "ul"
tab_bar = "reverse"
tab_active = "ul"
even = ""
odd = ""
selection = "reverse"
multiselect = "-1 6"
scrollbar = ""
}
streams = {
"dnbradio.com" = "http://www.dnbradio.com/hi.m3u"

View File

@@ -0,0 +1,51 @@
# Contributed by vifino
# Best enjoyed with the following softer terminal color theme:
#! special
#*.foreground: #d5d5d5
#*.background: #1d2021
#*.cursorColor: #d5d5d5
#! black
#*.color0: #101010
#*.color8: #6f6f6f
#! red
#*.color1: #ff6878
#*.color9: #ff778b
#! green
#*.color2: #b4fb73
#*.color10: #d0ffa0
#! yellow
#*.color3: #fff090
#*.color11: #fffeb0
#! blue
#*.color4: #6095ff
#*.color12: #80c0ff
#! magenta
#*.color5: #ff90fe
#*.color13: #f0a9ff
#! cyan
#*.color6: #45e1f8
#*.color14: #90e9ff
#! white
#*.color7: #f1f1f1
#*.color15: #ffffff
colors = {
normal = "1 0"
highlight = "12 0 bold"
elapsed = "4 4"
remains = "4 8"
tab_bar = "8 0"
tab_active = "6 8 bold"
even = "11 0"
odd = "11 0"
scrollbar = "8 0"
selection = "0 4"
multiselect = "0 3"
directory = "15 0"
incoming = "2"
outgoing = "4"
}

View File

@@ -0,0 +1,19 @@
colors = {
normal = "237 255"
highlight = "16 255 bold"
elapsed = "231 250"
remains = "250 231"
tab_bar = "252 16"
tab_active = "231 237 bold"
even = "16 231"
odd = "16 231"
scrollbar = "250 231"
selection = "231 202"
multiselect = "231 88"
directory = "16 231 bold"
incoming = "28"
outgoing = "19"
}

288
line-editor.c Normal file
View File

@@ -0,0 +1,288 @@
/*
* line-editor.c: a line editor component for the TUI part of liberty
*
* Copyright (c) 2017 - 2018, Přemysl Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
// This is here just for IDE code model reasons
#ifndef HAVE_LIBERTY
#include "liberty/liberty.c"
#include "liberty/liberty-tui.c"
#endif
static void
row_buffer_append_c (struct row_buffer *self, ucs4_t c, chtype attrs)
{
struct row_char current = { .attrs = attrs, .c = c };
struct row_char invalid = { .attrs = attrs, .c = '?', .width = 1 };
current.width = uc_width (current.c, locale_charset ());
if (current.width < 0 || !app_is_character_in_locale (current.c))
current = invalid;
ARRAY_RESERVE (self->chars, 1);
self->chars[self->chars_len++] = current;
self->total_width += current.width;
}
// --- Line editor -------------------------------------------------------------
enum line_editor_action
{
LINE_EDITOR_B_CHAR, ///< Go back a character
LINE_EDITOR_F_CHAR, ///< Go forward a character
LINE_EDITOR_B_WORD, ///< Go back a word
LINE_EDITOR_F_WORD, ///< Go forward a word
LINE_EDITOR_HOME, ///< Go to start of line
LINE_EDITOR_END, ///< Go to end of line
LINE_EDITOR_B_DELETE, ///< Delete last character
LINE_EDITOR_F_DELETE, ///< Delete next character
LINE_EDITOR_B_KILL_WORD, ///< Delete last word
LINE_EDITOR_B_KILL_LINE, ///< Delete everything up to BOL
LINE_EDITOR_F_KILL_LINE, ///< Delete everything up to EOL
};
struct line_editor
{
int point; ///< Caret index into line data
ucs4_t *line; ///< Line data, 0-terminated
int *w; ///< Codepoint widths, 0-terminated
size_t len; ///< Editor length
size_t alloc; ///< Editor allocated
char prompt; ///< Prompt character
void (*on_changed) (void); ///< Callback on text change
void (*on_end) (bool); ///< Callback on abort
};
static void
line_editor_free (struct line_editor *self)
{
free (self->line);
free (self->w);
}
/// Notify whomever invoked the editor that it's been either confirmed or
/// cancelled and clean up editor state
static void
line_editor_abort (struct line_editor *self, bool status)
{
self->on_end (status);
self->on_changed = NULL;
free (self->line);
self->line = NULL;
free (self->w);
self->w = NULL;
self->alloc = 0;
self->len = 0;
self->point = 0;
self->prompt = 0;
}
/// Start the line editor; remember to fill in "change" and "end" callbacks
static void
line_editor_start (struct line_editor *self, char prompt)
{
self->alloc = 16;
self->line = xcalloc (sizeof *self->line, self->alloc);
self->w = xcalloc (sizeof *self->w, self->alloc);
self->len = 0;
self->point = 0;
self->prompt = prompt;
}
static void
line_editor_changed (struct line_editor *self)
{
self->line[self->len] = 0;
self->w[self->len] = 0;
if (self->on_changed)
self->on_changed ();
}
static void
line_editor_move (struct line_editor *self, int to, int from, int len)
{
memmove (self->line + to, self->line + from,
sizeof *self->line * len);
memmove (self->w + to, self->w + from,
sizeof *self->w * len);
}
static void
line_editor_insert (struct line_editor *self, ucs4_t codepoint)
{
while (self->alloc - self->len < 2 /* inserted + sentinel */)
{
self->alloc <<= 1;
self->line = xreallocarray
(self->line, sizeof *self->line, self->alloc);
self->w = xreallocarray
(self->w, sizeof *self->w, self->alloc);
}
line_editor_move (self, self->point + 1, self->point,
self->len - self->point);
self->line[self->point] = codepoint;
self->w[self->point] = app_is_character_in_locale (codepoint)
? uc_width (codepoint, locale_charset ())
: 1 /* the replacement question mark */;
self->point++;
self->len++;
line_editor_changed (self);
}
static bool
line_editor_action (struct line_editor *self, enum line_editor_action action)
{
switch (action)
{
default:
return soft_assert (!"unknown line editor action");
case LINE_EDITOR_B_CHAR:
if (self->point < 1)
return false;
do self->point--;
while (self->point > 0
&& !self->w[self->point]);
return true;
case LINE_EDITOR_F_CHAR:
if (self->point + 1 > (int) self->len)
return false;
do self->point++;
while (self->point < (int) self->len
&& !self->w[self->point]);
return true;
case LINE_EDITOR_B_WORD:
{
if (self->point < 1)
return false;
int i = self->point;
while (i && self->line[--i] == ' ');
while (i-- && self->line[i] != ' ');
self->point = ++i;
return true;
}
case LINE_EDITOR_F_WORD:
{
if (self->point + 1 > (int) self->len)
return false;
int i = self->point;
while (i < (int) self->len && self->line[i] != ' ') i++;
while (i < (int) self->len && self->line[i] == ' ') i++;
self->point = i;
return true;
}
case LINE_EDITOR_HOME:
self->point = 0;
return true;
case LINE_EDITOR_END:
self->point = self->len;
return true;
case LINE_EDITOR_B_DELETE:
{
if (self->point < 1)
return false;
int len = 1;
while (self->point - len > 0
&& !self->w[self->point - len])
len++;
line_editor_move (self, self->point - len, self->point,
self->len - self->point);
self->len -= len;
self->point -= len;
line_editor_changed (self);
return true;
}
case LINE_EDITOR_F_DELETE:
{
if (self->point + 1 > (int) self->len)
return false;
int len = 1;
while (self->point + len < (int) self->len
&& !self->w[self->point + len])
len++;
self->len -= len;
line_editor_move (self, self->point, self->point + len,
self->len - self->point);
line_editor_changed (self);
return true;
}
case LINE_EDITOR_B_KILL_WORD:
{
if (self->point < 1)
return false;
int i = self->point;
while (i && self->line[--i] == ' ');
while (i-- && self->line[i] != ' ');
i++;
line_editor_move (self, i, self->point, (self->len - self->point));
self->len -= self->point - i;
self->point = i;
line_editor_changed (self);
return true;
}
case LINE_EDITOR_B_KILL_LINE:
self->len -= self->point;
line_editor_move (self, 0, self->point, self->len);
self->point = 0;
line_editor_changed (self);
return true;
case LINE_EDITOR_F_KILL_LINE:
self->len = self->point;
line_editor_changed (self);
return true;
}
}
static int
line_editor_write (const struct line_editor *self, struct row_buffer *row,
int width, chtype attrs)
{
if (self->prompt)
{
hard_assert (self->prompt < 127);
row_buffer_append_c (row, self->prompt, attrs);
width--;
}
int following = 0;
for (size_t i = self->point; i < self->len; i++)
following += self->w[i];
int preceding = 0;
size_t start = self->point;
while (start && preceding < width / 2)
preceding += self->w[--start];
// There can be one extra space at the end of the line but this way we
// don't need to care about non-spacing marks following full-width chars
while (start && width - preceding - following > 2 /* widest char */)
preceding += self->w[--start];
// XXX: we should also show < > indicators for overflow but it'd probably
// considerably complicate this algorithm
for (; start < self->len; start++)
row_buffer_append_c (row, self->line[start], attrs);
return !!self->prompt + preceding;
}

898
nncmpp.c

File diff suppressed because it is too large Load Diff