Skip to content

Commit b3c1bbb

Browse files
committed
[FEAT:MED] CHANGELOG v2.3
1 parent ed99ee4 commit b3c1bbb

File tree

14 files changed

+204
-65
lines changed

14 files changed

+204
-65
lines changed

CHANGELOG/v2_3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CHANGE TYPE: MEDIUM
2+
3+
-> Added audio file preview (VISUAL) with error handling and testing
4+
5+
-> Files with no extension and non-executable now show in as bash script file with syntax highlighting by default
6+
7+
-> Updated arguments for litefm

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@ set(CMAKE_C_STANDARD 99)
3535
find_package(Curses REQUIRED)
3636
find_package(PkgConfig REQUIRED)
3737
pkg_check_modules(LIBARCHIVE REQUIRED libarchive)
38-
# Manually specify YAML include and library paths
3938
pkg_check_modules(LIBYAML REQUIRED yaml-0.1)
39+
pkg_check_modules(SDL2 REQUIRED sdl2)
40+
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)
4041

41-
42-
# Include directories for ncurses, libarchive, libyaml, and project headers
42+
# Include directories for ncurses, libarchive, libyaml, SDL2, SDL2_mixer, and project headers
4343
include_directories(${CURSES_INCLUDE_DIR})
4444
include_directories(${LIBARCHIVE_INCLUDE_DIRS})
4545
include_directories(${LIBYAML_INCLUDE_DIRS})
46+
include_directories(${SDL2_INCLUDE_DIRS})
47+
include_directories(${SDL2_MIXER_INCLUDE_DIRS})
4648
include_directories(${CMAKE_SOURCE_DIR})
4749

4850
# Add the executable
49-
add_executable(litefm lfm.c src/cursesutils.c src/filepreview.c src/dircontrol.c src/archivecontrol.c src/clipboard.c src/logging.c src/signalhandling.c src/highlight.c src/hashtable.c src/helpers.c)
51+
add_executable(litefm lfm.c src/cursesutils.c src/filepreview.c src/dircontrol.c src/archivecontrol.c src/clipboard.c src/logging.c src/signalhandling.c src/highlight.c src/hashtable.c src/arg_helpers.c src/musicpreview.c)
5052

5153
# Link required libraries
52-
target_link_libraries(litefm ${CURSES_LIBRARIES} ${LIBARCHIVE_LIBRARIES} ${LIBYAML_LIBRARIES})
54+
target_link_libraries(litefm ${CURSES_LIBRARIES} ${LIBARCHIVE_LIBRARIES} ${LIBYAML_LIBRARIES} ${SDL2_LIBRARIES} ${SDL2_MIXER_LIBRARIES})
5355

5456
# Add additional compiler flags
5557
target_compile_options(litefm PRIVATE -Wall -Wextra -Wpedantic)

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ ARCHIVE_INCS = $(shell pkg-config --cflags libarchive)
3636
YAML_LIBS = $(shell pkg-config --libs yaml-0.1)
3737
YAML_INCS = $(shell pkg-config --cflags yaml-0.1)
3838

39+
SDL2_LIBS = $(shell pkg-config --libs sdl2)
40+
SDL2_INCS = $(shell pkg-config --cflags sdl2)
41+
SDL2_MIXER_LIBS = $(shell pkg-config --libs sdl2_mixer)
42+
SDL2_MIXER_INCS = $(shell pkg-config --cflags sdl2_mixer)
43+
3944
# Source files
4045
SRCS = lfm.c \
4146
src/cursesutils.c \
@@ -47,7 +52,8 @@ SRCS = lfm.c \
4752
src/signalhandling.c \
4853
src/highlight.c \
4954
src/hashtable.c \
50-
src/helpers.c
55+
src/arg_helpers.c \
56+
src/musicpreview.c
5157

5258
# Object files
5359
OBJS = $(SRCS:.c=.o)
@@ -60,11 +66,11 @@ all: $(TARGET)
6066

6167
# Link the executable
6268
$(TARGET): $(OBJS)
63-
$(CC) -o $@ $(OBJS) $(CURSES_LIBS) $(ARCHIVE_LIBS) $(YAML_LIBS)
69+
$(CC) -o $@ $(OBJS) $(CURSES_LIBS) $(ARCHIVE_LIBS) $(YAML_LIBS) $(SDL2_LIBS) $(SDL2_MIXER_LIBS)
6470

6571
# Compile source files into object files
6672
%.o: %.c
67-
$(CC) $(CFLAGS) $(CURSES_INCS) $(ARCHIVE_INCS) $(YAML_INCS) -c $< -o $@
73+
$(CC) $(CFLAGS) $(CURSES_INCS) $(ARCHIVE_INCS) $(YAML_INCS) $(SDL2_INCS) $(SDL2_MIXER_INCS) -c $< -o $@
6874

6975
# Clean up generated files
7076
clean:

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,12 @@ Written in C with NCurses, libyaml, rsync and more!
2929
>
3030
> Without a nerd font, LiteFM will show some unreadable chars!
3131
>
32-
> **2. Have it full screen whenever possible:**
32+
> **2. Dynamic resizing:**
3333
>
34-
> Despite having dynamic window scaling, in a lot of
35-
> the outputs the strings may look weird (or not visible at all!) upon resizing.
36-
> Therefore, till I find a way to fix this issue, it is **HIGHLY**
37-
> recommended to use LiteFM at:
34+
> There is dynamic windowing setup in LiteFM. However,
3835
>
39-
> -> Full screen of originally created terminal [DE]
36+
> Upon resizing, you will have to press any key for it to show!
4037
>
41-
> -> Full terminal size without resizing [WM]
42-
>
4338
> **3. Launch LiteFM with `superuser`**
4439
>
4540
> LiteFM allows for fast file/dir actions,
File renamed without changes.

include/filepreview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const char *determine_file_type(const char *filename);
5959
int is_readable_extension(const char *filename);
6060
const char *format_file_size(off_t size);
6161
int is_image(const char *filename);
62+
int is_audio(const char *filename);
6263
void launch_env_var(WINDOW* win, const char *current_path, const char *filename, const char* type);
6364
void print_permissions(WINDOW *info_win, struct stat *file_stat);
6465
void display_archive_contents(WINDOW *info_win, const char *full_path, const char *file_ext);

include/musicpreview.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef MUSIC_H
2+
#define MUSIC_H
3+
4+
#include <unistd.h>
5+
#include <sys/types.h>
6+
#include <sys/wait.h>
7+
#include <signal.h>
8+
#include <stdlib.h>
9+
#include <stdio.h>
10+
#include <SDL2/SDL.h>
11+
#include <SDL2/SDL_mixer.h>
12+
#include <ncurses.h>
13+
14+
void preview_audio(const char *file_path);
15+
16+
#endif

keywords/sh-keywords.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ symbols:
6969
- '<'
7070
- '>'
7171
- '$'
72-
- '`'
7372
- '~'
7473
- '\\'
7574
- '='
@@ -99,3 +98,5 @@ multicomments2:
9998
strings:
10099
- "\""
101100
- "'"
101+
- "`"
102+
- "\"\""

lfm.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
#include "include/signalhandling.h"
4747
#include "include/highlight.h"
4848
#include "include/hashtable.h"
49-
#include "include/helpers.h"
49+
#include "include/arg_helpers.h"
50+
#include "include/musicpreview.h"
5051

5152
#define MAX_ITEMS 1024
5253
#define MAX_HISTORY 256
@@ -762,6 +763,17 @@ int main(int argc, char* argv[]) {
762763
endwin();
763764
show_version();
764765
return 0;
766+
} else if (argc == 2 && (strcmp(argv[1], "-l") == 0 || strcmp(argv[1], "--log-dir") == 0)) {
767+
endwin();
768+
printf("Log file at: ~/%s\n", LOG_FILE_RELATIVE_PATH);
769+
return 0;
770+
} else if (argc == 2 && (strcmp(argv[1], "-lc") == 0 || strcmp(argv[1], "--log-clear") == 0)) {
771+
endwin();
772+
char termbuf[256];
773+
snprintf(termbuf, 256, "echo '' > ~/%s", LOG_FILE_RELATIVE_PATH);
774+
system(termbuf);
775+
printf("Cleared log for LiteFM.\n"); // will implement this later
776+
return 0;
765777
} else {
766778
get_current_working_directory(current_path, sizeof(current_path));
767779
}
@@ -788,6 +800,7 @@ int main(int argc, char* argv[]) {
788800
int find_index = 0;
789801
char last_query[NAME_MAX] = "";
790802
bool firstKeyPress = true;
803+
bool firstPlay = true;
791804
log_message(LOG_LEVEL_DEBUG, "================ LITEFM INSTANCE STARTED =================");
792805
log_message(LOG_LEVEL_DEBUG, "Entering as USER: %s",cur_user);
793806

@@ -892,13 +905,19 @@ int main(int argc, char* argv[]) {
892905
highlight = 0;
893906
scroll_position = 0;
894907
} else {
895-
if ((is_readable_extension(items[highlight].name) || !is_image(items[highlight].name)) && !items[highlight].is_dir) {
908+
if ((is_readable_extension(items[highlight].name) || !is_image(items[highlight].name)) && !items[highlight].is_dir && !is_audio(items[highlight].name)) {
896909
firstKeyPress = true;
897910
launch_env_var(win, current_path, items[highlight].name, "EDITOR");
898911
/* Since we have set firstKeyPress to true, it will not wgetch(), rather it will just refresh everything back to how it was */
899912
} else if (is_image(items[highlight].name) && !items[highlight].is_dir) {
900913
firstKeyPress = true;
901914
launch_env_var(win, current_path, items[highlight].name, "VISUAL");
915+
} else if (is_audio(items[highlight].name) && !items[highlight].is_dir) {
916+
char file_path[MAX_PATH_LENGTH];
917+
snprintf(file_path, MAX_PATH_LENGTH, "%s/%s", current_path, items[highlight].name);
918+
show_term_message(" [PREVIEW] Previewing audio file. Press q to quit.", 0);
919+
preview_audio(file_path);
920+
show_term_message("", -1);
902921
} else {
903922
show_term_message("Cannot enter this directory/file.", 1);
904923
}
@@ -1456,9 +1475,6 @@ int main(int argc, char* argv[]) {
14561475
}
14571476
break;
14581477
}
1459-
/*else if (nextch == 'p' && !items[highlight].is_dir) {*/
1460-
/* break;*/
1461-
/*}*/
14621478
refreshMainWin(win, info_win, items, item_count, highlight, current_path, show_hidden, scroll_position, height, info_height, info_width, info_starty, info_startx);
14631479

14641480
} while (nextch != 10);

src/helpers.c renamed to src/arg_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "../include/helpers.h"
2+
#include "../include/arg_helpers.h"
33

44
void show_help() {
55
// Print the header in blue color

0 commit comments

Comments
 (0)