Skip to content

Commit

Permalink
Added scroll and other things to search
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol committed Jun 17, 2024
1 parent b0d87f2 commit a40e2a5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/kew-manpage.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Go to first song.
Go to specific song number in the playlist.
.It G
Go to last song.
.It q
.It Esc
Quit
.Nm .
.El
Expand Down
2 changes: 1 addition & 1 deletion docs/kew.1
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Go to specific song number in the playlist.
G
Go to last song.
.TP 9n
q
Esc
Quit
\fBkew\fR.
.SH "FILES"
Expand Down
2 changes: 2 additions & 0 deletions src/kew.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ struct Event processInput()
{settings.volumeDown, EVENT_VOLUME_DOWN},
{settings.togglePause, EVENT_PLAY_PAUSE},
{settings.quit, EVENT_QUIT},
{settings.hardQuit, EVENT_QUIT},
{settings.toggleShuffle, EVENT_SHUFFLE},
{settings.toggleCovers, EVENT_TOGGLECOVERS},
{settings.toggleVisualizer, EVENT_TOGGLEVISUALIZER},
Expand Down Expand Up @@ -213,6 +214,7 @@ struct Event processInput()
{settings.hardShowTrackAlt, EVENT_SHOWTRACK},
{settings.hardShowLibrary, EVENT_SHOWLIBRARY},
{settings.hardShowLibraryAlt, EVENT_SHOWLIBRARY},
{settings.hardShowSearchAlt, EVENT_SHOWSEARCH},
{settings.hardNextPage, EVENT_NEXTPAGE},
{settings.hardPrevPage, EVENT_PREVPAGE},
{settings.hardRemove, EVENT_REMOVE}};
Expand Down
36 changes: 23 additions & 13 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct
#endif

const char VERSION[] = "2.5.0";
const int ABSOLUTE_MIN_WIDTH = 66;
const int ABSOLUTE_MIN_WIDTH = 68;
bool visualizerEnabled = true;
bool coverEnabled = true;
bool hideLogo = false;
Expand Down Expand Up @@ -63,10 +63,12 @@ double pauseSeconds = 0.0;
double totalPauseSeconds = 0.0;
double seekAccumulatedSeconds = 0.0;
int maxListSize = 0;
int maxSearchListSize = 0;

int numDirectoryTreeEntries = 0;
int numTopLevelSongs = 0;
int startLibIter = 0;
int startSearchIter = 0;
int maxLibListSize = 0;
int chosenLibRow = 0;
int chosenSearchResultRow = 0;
Expand Down Expand Up @@ -179,7 +181,7 @@ void printHelp()
printf(" Press F5 to search.\n");
printf(" Press F6 to display key bindings.\n");
printf(" Press . to add the currently playing song to kew.m3u.\n");
printf(" Press q to quit.\n");
printf(" Press Esc to quit.\n");
printf("\n");
}

Expand Down Expand Up @@ -497,7 +499,7 @@ void printLastRow()
return;
setTextColorRGB(lastRowColor.r, lastRowColor.g, lastRowColor.b);

char text[100] = " [F2 Playlist|F3 Library|F4 Track|F5 Search|F6 Keys|Q Quit]";
char text[100] = " [F2 Playlist|F3 Library|F4 Track|F5 Search|F6 Keys|Esc Quit]";

char nerdFontText[100] = "";

Expand Down Expand Up @@ -618,7 +620,7 @@ int showKeyBindings(SongData *songdata, AppSettings *settings)
printBlankSpaces(indent);
printf(" - %s to add current song to kew.m3u (run with \"kew .\").\n", settings->addToMainPlaylist);
printBlankSpaces(indent);
printf(" - %s to quit.\n", settings->quit);
printf(" - Esc or %s to quit.\n", settings->quit);
printf("\n");
printLastRow();

Expand Down Expand Up @@ -703,7 +705,10 @@ void flipNextPage()
}
else if (appState.currentView == SEARCH_VIEW)
{
// FIXME: IMPLEMENT THIS
chosenSearchResultRow += maxSearchListSize -1;
chosenSearchResultRow = (chosenSearchResultRow >= getSearchResultsCount()) ? getSearchResultsCount() - 1 : chosenSearchResultRow;
startSearchIter += maxSearchListSize - 1;
refresh = true;
}
}

Expand All @@ -723,7 +728,10 @@ void flipPrevPage()
}
else if (appState.currentView == SEARCH_VIEW)
{
// FIXME: IMPLEMENT THIS
chosenSearchResultRow -= maxSearchListSize;
chosenSearchResultRow = (chosenSearchResultRow > 0) ? chosenSearchResultRow : 0;
startSearchIter -= maxSearchListSize;
refresh = true;
}
}

Expand Down Expand Up @@ -800,16 +808,16 @@ void showSearch(SongData *songData, int *chosenRow)
{
int term_w, term_h;
getTermSize(&term_w, &term_h);
maxListSize = term_h - 5;
maxSearchListSize = term_h - 5;

int aboutRows = printLogo(songData);
maxListSize -= aboutRows;
maxSearchListSize -= aboutRows;

printBlankSpaces(indent);
printf(" Use ↑, ↓ or k, j to choose. Enter to accept.\n\n");
maxListSize -= 2;
printf(" Use ↑, ↓ to choose. Enter to accept.\n\n");
maxSearchListSize -= 2;

displaySearch(maxListSize, indent, chosenRow);
displaySearch(maxSearchListSize, indent, chosenRow, startSearchIter);

printf("\n");
printLastRow();
Expand Down Expand Up @@ -948,8 +956,10 @@ void processName(const char *name, char *output, int maxWidth)

void setChosenDir(FileSystemEntry *entry)
{
if (currentEntry->isDirectory)
chosenDir = entry;
if (entry->isDirectory)
{
currentEntry = chosenDir = entry;
}
}

void setCurrentAsChosenDir()
Expand Down
2 changes: 1 addition & 1 deletion src/playerops.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Node *getNextSong();

void handleRemove();

void enqueueSongs();
void enqueueSongs(FileSystemEntry *entry);

void updateLastSongSwitchTime(void);

Expand Down
36 changes: 23 additions & 13 deletions src/search_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ FileSystemEntry *getCurrentSearchEntry()
return currentSearchEntry;
}

int getSearchResultsCount()
{
return resultsCount;
}

// Function to add a result to the global array
void addResult(FileSystemEntry *entry, int distance)
{
Expand Down Expand Up @@ -202,7 +207,7 @@ int removeFromSearchText()
return 0;
}

int displaySearchResults(int maxListSize, int indent, int *chosenRow)
int displaySearchResults(int maxListSize, int indent, int *chosenRow, int startSearchIter)
{
int term_w, term_h;
getTermSize(&term_w, &term_h);
Expand All @@ -212,25 +217,34 @@ int displaySearchResults(int maxListSize, int indent, int *chosenRow)

sortResults();

if (*chosenRow >= (int)resultsCount - 1 || *chosenRow >= maxListSize - 1)
if (*chosenRow >= (int)resultsCount - 1)
{
*chosenRow = MIN(resultsCount, maxListSize) - 1;
*chosenRow = resultsCount - 1;
}

if (*chosenRow < 0)
if (startSearchIter < 0)
startSearchIter = 0;

if (*chosenRow > startSearchIter + round(maxListSize / 2))
{
*chosenRow = 0;
startSearchIter = *chosenRow - round(maxListSize / 2) + 1;
}

if (*chosenRow < startSearchIter)
startSearchIter = *chosenRow;

if (*chosenRow < 0)
startSearchIter = *chosenRow = 0;

printf("\n");

// Print the sorted results
for (size_t i = 0; i < resultsCount; i++)
for (size_t i = startSearchIter; i < resultsCount; i++)
{
if (numSearchLetters < minSearchLetters)
break;

if ((int)i >= maxListSize)
if ((int)i >= (maxListSize + startSearchIter))
break;

setDefaultTextColor();
Expand Down Expand Up @@ -283,14 +297,10 @@ int displaySearchResults(int maxListSize, int indent, int *chosenRow)
return 0;
}

int displaySearch(int maxListSize, int indent, int *chosenRow)
int displaySearch(int maxListSize, int indent, int *chosenRow, int startSearchIter)
{
displaySearchBox(indent);
displaySearchResults(maxListSize, indent, chosenRow);
displaySearchResults(maxListSize, indent, chosenRow, startSearchIter);

return 0;
}

// FIXME: page up page down
// FIXME: scroll into view
// FIXME: quit in search view. esc to quit? esc to quit search?
4 changes: 3 additions & 1 deletion src/search_ui.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include <stdbool.h>
#include <math.h>
#include "directorytree.h"
#include "term.h"
#include "common_ui.h"

extern bool newUndisplayedSearch;

int displaySearch(int maxListSize, int indent, int *chosenRow);
int displaySearch(int maxListSize, int indent, int *chosenRow, int startSearchIter);
int addToSearchText(const char *str);
int removeFromSearchText();
int getSearchResultsCount();
void fuzzySearch(FileSystemEntry *root, int threshold);
void freeSearchResults();
FileSystemEntry *getCurrentSearchEntry();
1 change: 1 addition & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ AppSettings constructAppSettings(KeyValuePair *pairs, int count)
strncpy(settings.titleColor, "6", sizeof(settings.titleColor));
strncpy(settings.enqueuedColor, "7", sizeof(settings.enqueuedColor));
strncpy(settings.quit, "q", sizeof(settings.quit));
strncpy(settings.hardQuit, "\x1B", sizeof(settings.hardQuit));

if (pairs == NULL)
{
Expand Down
1 change: 1 addition & 0 deletions src/soundcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ typedef struct
char addToMainPlaylist[6];
char updateLibrary[6];
char quit[6];
char hardQuit[6];
char hardSwitchNumberedSong[6];
char hardPlayPause[6];
char hardPrev[6];
Expand Down

0 comments on commit a40e2a5

Please sign in to comment.