X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Fcli%2FCliReader.java;h=03cb22738b37b1f25cb4ff9c5c73d2d4bcb5ff82;hb=53f76130c5337a77362b191f22115b461811ba36;hp=7a4abfb28c91490f92dd50140c10eb9e1404e134;hpb=91b82a5cbd8a9c90798d1bd49bfa9a061e652a6a;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/cli/CliReader.java b/src/be/nikiroo/fanfix/reader/cli/CliReader.java index 7a4abfb..03cb227 100644 --- a/src/be/nikiroo/fanfix/reader/cli/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/cli/CliReader.java @@ -14,6 +14,7 @@ import be.nikiroo.fanfix.reader.BasicReader; import be.nikiroo.fanfix.searchable.BasicSearchable; import be.nikiroo.fanfix.searchable.SearchableTag; import be.nikiroo.fanfix.supported.SupportType; +import be.nikiroo.utils.StringUtils; /** * Command line {@link Story} reader. @@ -99,28 +100,29 @@ class CliReader extends BasicReader { + author); } } - + @Override - public void search(SupportType searchOn, String keywords, int page, int item) throws IOException { - + public void search(SupportType searchOn, String keywords, int page, int item) + throws IOException { + } - + @Override - public void searchTag(SupportType searchOn, int page, int item, String... tags) throws IOException { + public void searchTag(SupportType searchOn, int page, int item, + String... tags) throws IOException { BasicSearchable search = BasicSearchable.getSearchable(searchOn); List stags = search.getTags(); - - + SearchableTag stag = null; for (String tag : tags) { stag = null; - for (int i = 0 ; i < stags.size() ; i++) { + for (int i = 0; i < stags.size(); i++) { if (stags.get(i).getName().equalsIgnoreCase(tag)) { stag = stags.get(i); break; } } - + if (stag != null) { search.fillTag(stag); stags = stag.getChildren(); @@ -133,6 +135,7 @@ class CliReader extends BasicReader { if (stag != null) { if (page <= 0) { if (stag.isLeaf()) { + search.search(stag, 1); System.out.println(stag.getPages()); } else { System.out.println(stag.getCount()); @@ -141,7 +144,7 @@ class CliReader extends BasicReader { List metas = null; List subtags = null; int count; - + if (stag.isLeaf()) { metas = search.search(stag, page); count = metas.size(); @@ -149,12 +152,14 @@ class CliReader extends BasicReader { subtags = stag.getChildren(); count = subtags.size(); } - + if (item > 0) { if (item <= count) { if (metas != null) { MetaData meta = metas.get(item - 1); - System.out.println(item + ": " + meta.getTitle()); + System.out.println(page + "/" + item + ": " + + meta.getTitle()); + System.out.println(); System.out.println(meta.getUrl()); System.out.println(); System.out.println("Tags: " + meta.getTags()); @@ -165,26 +170,66 @@ class CliReader extends BasicReader { } } else { SearchableTag subtag = subtags.get(item - 1); - // TODO: display fixed info, not debug - System.out.println(subtag); + + String sp = ""; + if (subtag.getParent() != null) { + List parents = new ArrayList(); + for (SearchableTag parent = subtag.getParent(); parent != null; parent = parent + .getParent()) { + parents.add(parent.getName()); + } + for (String parent : parents) { + if (!sp.isEmpty()) { + sp += " / "; + } + sp += parent; + } + } + + // TODO: i18n + String stories = "stories"; + String num = StringUtils.formatNumber(subtag + .getCount()); + if (sp.isEmpty()) { + System.out.println(String.format( + "%d/%d: %s, %s %s", page, item, + subtag.getName(), num, stories)); + } else { + System.out.println(String.format( + "%d/%d: %s (%s), %s %s", page, item, + subtag.getName(), sp, num, stories)); + } } } else { - System.out.println("Invalid item: only " + count + " items found"); + System.out.println("Invalid item: only " + count + + " items found"); } } else { if (metas != null) { int i = 0; for (MetaData meta : metas) { - System.out.println((i + 1) + ": " + meta.getTitle()); + System.out + .println((i + 1) + ": " + meta.getTitle()); i++; } } else { + int i = 1; for (SearchableTag subtag : subtags) { + String total = ""; if (subtag.getCount() > 0) { - System.out.println(subtag.getName() + " (" + subtag.getCount() + ")"); + total = StringUtils.formatNumber(subtag + .getCount()); + } + + if (total.isEmpty()) { + System.out.println(String.format("%d: %s", i, + subtag.getName())); } else { - System.out.println(subtag.getName()); + System.out.println(String.format("%d: %s (%s)", + i, subtag.getName(), total)); } + + i++; } } }