History

command: don't print unneeded new lines for track-list

Useful for terminal output.

Guido Cella committed 2 years ago

Commit 8aad03b1 parent 153d4921 file · +20 −9Browse files

Unified · Split

player/command.c+20−9
@@ -2115,7 +2115,6 @@ static char *append_track_info(char *res, struct track *track) · 2114 unmodified lines
21152115 res = talloc_asprintf_append(res, "(%s) ", track->lang);
21162116 if (track->is_external)
21172117 res = talloc_asprintf_append(res, "(external) ");
2118− res = talloc_asprintf_append(res, "\n");
21192118
21202119 return res;
21212120 }
@@ -2125,25 +2124,35 @@ static int property_list_tracks(void *ctx, struct m_property *prop, · 3 unmodified lines
21252124 {
21262125 MPContext *mpctx = ctx;
21272126 if (action == M_PROPERTY_PRINT) {
2128− char *res = NULL;
2127+ char *res = talloc_strdup(NULL, "");
21292128
21302129 for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
2130+ bool found = false;
2131+
21312132 for (int n = 0; n < mpctx->num_tracks; n++) {
21322133 struct track *track = mpctx->tracks[n];
21332134 if (track->type == type) {
21342135 res = talloc_asprintf_append(res, "%s: ", track_type_name(track));
21352136 res = append_track_info(res, track);
2137+ res = talloc_asprintf_append(res, "\n");
2138+ found = true;
21362139 }
21372140 }
21382141
2139− res = talloc_asprintf_append(res, "\n");
2142+ if (found && type < STREAM_TYPE_COUNT - 1) {
2143+ res = talloc_asprintf_append(res, "\n");
2144+ found = false;
2145+ }
21402146 }
21412147
21422148 struct demuxer *demuxer = mpctx->demuxer;
2143− if (demuxer && demuxer->num_editions > 1)
2144− res = talloc_asprintf_append(res, "\nEdition: %d of %d\n",
2145− demuxer->edition + 1,
2146− demuxer->num_editions);
2149+ if (demuxer && demuxer->num_editions > 1) {
2150+ res = talloc_asprintf_append(res, "\nEdition: %d of %d",
2151+ demuxer->edition + 1,
2152+ demuxer->num_editions);
2153+ } else {
2154+ res[strlen(res) - 1] = '\0';
2155+ }
21472156
21482157 *(char **)arg = res;
21492158 return M_PROPERTY_OK;
@@ -2169,12 +2178,14 @@ static int property_list_tracks(void *ctx, struct m_property *prop, · 19 unmodified lines
21692178 *(struct m_option *)ka->arg = (struct m_option){.type = CONF_TYPE_STRING};
21702179 return M_PROPERTY_OK;
21712180 case M_PROPERTY_PRINT:
2172− res = talloc_asprintf(NULL, "Available %s tracks:\n",
2181+ res = talloc_asprintf(NULL, "Available %s tracks:",
21732182 type == STREAM_SUB ? "subtitle" : stream_type_name(type));
21742183
21752184 for (int n = 0; n < mpctx->num_tracks; n++) {
2176− if (mpctx->tracks[n]->type == type)
2185+ if (mpctx->tracks[n]->type == type) {
2186+ res = talloc_strdup_append(res, "\n");
21772187 res = append_track_info(res, mpctx->tracks[n]);
2188+ }
21782189 }
21792190
21802191 *(char **)ka->arg = res;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t