10 Commits a79139d3d8 ... 93efe87cfa

Author SHA1 Message Date
  Jeison Yehuda Amihud (Blender Dumbass) 93efe87cfa Notabug theme 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) 3eacef97f3 Upload files to 'themes' 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) a3b84a3fd6 Upload files to 'themes' 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) f832d24d38 LBRY Desktop Theme 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) f54543b56c Odysee Dark Theme 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) 228f6b4fca Themes 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) 2be8da9a88 Upload files to 'themes' 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) 4a49237c5e Themes 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) 1f025d9549 Themes 3 years ago
  Jeison Yehuda Amihud (Blender Dumbass) ee3b34f469 restore edit / delete comments 3 years ago
10 changed files with 345 additions and 5 deletions
  1. 52 2
      flbry/comments.py
  2. 146 0
      flbry/settings.py
  3. 61 0
      help/themes.md
  4. 18 3
      run.py
  5. 6 0
      themes/BlenderDumbass2.0.json
  6. 6 0
      themes/LBRY_Desktop.json
  7. 6 0
      themes/Mastodon.json
  8. 7 0
      themes/NotAbug.json
  9. 43 0
      themes/default.json
  10. 0 0
      themes/odysee.json

+ 52 - 2
flbry/comments.py

@@ -184,7 +184,9 @@ def view(i):
          "read",
          "channel",
          "comments",
-         "reply"
+         "reply",
+         "delete",
+         "edit"
      ])
      
      # let's implement commands
@@ -214,7 +216,20 @@ def view(i):
         elif c.startswith("reply"):
             c = c + ' '
             post(i["claim_id"], c[c.find(" "):], i["comment_id"])
-            
+
+        elif c == "delete":
+            out = check_output(["flbry/lbrynet", "comment", "abandon", i["comment_id"]])
+            out = json.loads(out)
+            try:
+                if out["abandoned"] == True:
+                    center("Comment deleted!", "bdgr")
+                    break
+            except:
+                if out["message"].startswith("Couldn't find channel with channel_id"):
+                    center("You can't delete a comment you didn't post", "bdrd")
+        elif c.startswith("edit"):
+            c = c + ' '
+            update(i, c[c.find(" "):])
 
 def post(claim_id, args,  parent_id=""):
 
@@ -532,3 +547,38 @@ def inbox(opt=10):
         view(items[c])
         c = input(typing_dots())
             
+def update(i, args):
+    comment = i["comment"]
+
+    if len(args) > 1:
+        a = args.split()[0]
+
+        try:
+            text = open(a, "r")
+            text = text.read()
+        except:
+            text = open("/tmp/fastlbrycommentwriter.txt", "w")
+            text.write(comment)
+            text.close()
+
+            import os
+            os.system(a+" /tmp/fastlbrycommentwriter.txt")
+
+            center("Press Enter when the file is ready and saved.")
+            input()
+
+            text = open("/tmp/fastlbrycommentwriter.txt", "r")
+            text = text.read()
+    else:
+        print("Comment: "+comment)
+        text = input("Edited comment: ")
+
+    out = check_output(["flbry/lbrynet",
+                "comment", "update", "--comment_id="+i["comment_id"],
+                "--comment="+text])
+    out = json.loads(out)
+    try:
+        if out["message"].startswith("Couldn't find channel with channel_id"):
+            center("You cant' edit a comment that isn't yours", "bdrd")
+    except:
+        center("Comment edited!", "bdgr")

+ 146 - 0
flbry/settings.py

@@ -28,6 +28,7 @@
 #####################################################################
 
 import os
+import json
 from flbry.variables import *
 
 # This file will manage settings / installation and stuff like this.
@@ -46,9 +47,80 @@ def get_settings_folder(flbry="flbry/"):
 
     return data_dir
     
+def check_config():
 
+    # This function checks whether config exists. If not makes a
+    # default setting.
 
+    default = {"theme":"default"}
+    
+    if not os.path.exists(get_settings_folder()+"config.json"):
+        with open(get_settings_folder()+"config.json", 'w') as f:
+                json.dump(default, f, indent=4, sort_keys=True)
+
+def get(key):
+
+    # This function gets a setting from settings.
+
+    with open(get_settings_folder()+"config.json") as f:
+        data = json.load(f)
+
+    try:
+        return data[key]
+    except:
+        return None
+
+def save(key, value):
+
+    # This function will save a value into the settings file.
+
+    with open(get_settings_folder()+"config.json") as f:
+        data = json.load(f)
+
+    data[key] = value
+
+    with open(get_settings_folder()+"config.json", 'w') as f:
+        json.dump(data, f, indent=4, sort_keys=True)
+    
+    
+def set_theme(theme):
+
+    # This will set a global theme
+
+    
+    user_themes = get_settings_folder()+"themes/"
+    default_themes = "themes/"
+    
+    # First let's see if user has a theme folder in settings.
+    try:
+        os.makedirs(user_themes)
+    except:
+        pass
+
+    # Trying to load the theme from user themes first
+    try:
+        with open(user_themes+theme+".json") as f:
+            data = json.load(f)
+    except Exception as e:
+       
+        try:
+            with open(default_themes+theme+".json") as f:
+                data = json.load(f)
+        except Exception as e:
+            
+            return
 
+    # Now let's actually apply the theme
+    from flbry import variables
+
+    for i in data:
+        if data[i] in variables.clr:
+            variables.clr[i] = clr[data[i]]
+        else:
+            variables.clr[i] = "\033["+data[i]+"m"
+
+    
+    
 def install_desktop(force=True):
 
     # This function will generate a .desktop file. And put it in
@@ -82,3 +154,77 @@ Categories=Network;AudioVideo"""
         center("Installed in Applications Menu", "bdgr")
     except:
         center("Installing in Applications Menu failed", "bdrd")
+
+def theme_ui():
+
+    # This is the ui for setting up themes.
+
+    themes = []
+    for i in os.listdir("themes"):
+        if i.endswith(".json"):
+            themes.append(i.replace(".json", ""))
+    for i in os.listdir(get_settings_folder()+"themes"):
+        if i.endswith(".json") and i.replace(".json", "") not in themes:
+            themes.append(i.replace(".json", ""))
+
+    d = {"categories":["Theme"],
+         "size":[1],
+         "data":[]}
+    for i in themes:
+        d["data"].append([i])
+    table(d)
+    center("Select Theme")
+
+    # User selects a theme
+    c = input(typing_dots())
+    try:
+        save("theme", themes[int(c)])
+    except:
+        save("theme", "default")
+
+    center("Theme set to: "+get("theme"), "bdgr")
+    set_theme(get("theme"))
+        
+        
+def ui():
+
+    # This will be the user interface for setting up setting.
+
+    with open(get_settings_folder()+"config.json") as f:
+        data = json.load(f)
+
+    d = {"categories":["name","value"],
+         "size":[1,1],
+         "data":[]}
+    
+    for i in data:
+        d["data"].append([i, data[i]])
+    table(d)
+
+    center("Type the number of setting to set")
+    
+    # user inputs the number
+    while True:
+        c = input(typing_dots())
+        try:
+            c = int(c)
+        except:
+            break
+
+        
+
+        # If editing theme
+        if list(data.keys())[c] == "theme":
+            theme_ui()
+    
+        else:
+        
+            value = input("    New Value:")
+
+            try:
+                save(list(data.keys())[c], value)
+                center("Setting was overwritten successfully.", "bdgr")
+            except Exception as e:
+                center("Error saving setting: "+str(e), "bdrd")
+
+        

+ 61 - 0
help/themes.md

@@ -0,0 +1,61 @@
+This file will explain you how to make themes for FastLBRY terminal. So if you have some imagination, you can make themes for this program.
+
+# Where Are Theme Files?
+
+There are two locations for themes. One is in the `themes` folder in the software it self. Those are maintained in the repository, so any change in those themes will be overwritten on update.
+
+The second place is `~/.local/share/flbry/themes` where you can store theme files too.
+
+# The format
+
+Themes are basically overwriting colors in the fastLBRY color preset. You can find the preset in `flbry/variables.py` toward the beginning of the file.
+
+Terminal has escape codes that if printed, will result in a mode change, or a color change. For example the mode `0` is normal text. Mode `1` is **bold text** and mode `3` is *italic text*.
+
+There are 3 levels of color detail. The one used in the preset originally using 16 colors. But there is a way to use 256 colors or a full spectrum RGB. So don't be afraid. Any colors you want, could be put into the theme.
+
+Let's look at the theme file. This is a test theme:
+
+```
+{"bdma":"bdcy",
+ "bdcy":"48;2;255;0;0"}
+```
+
+If you can see, the file is formatted in a json format. This theme overwrites two presets. `bdma` ( background dark magenta ) which is used most often in the default theme. And it sets it to `bdcy` ( background dark cyan ). The full list of codes are available in the `flbry/variables.py` file.
+
+The second line overwrites the `bdcy` variable with a custom color. Let's look at 3 ways of making a custom color.
+
+## 16 colors custom setting
+
+You can just write a simple number. For example a theme like this:
+
+```
+{"bdma":"44"}
+```
+
+In this example the `bdma` color will be overwritten with escape code `44`. Which is you look into the `flbry/variables.py` is a code for Dark Blue. You can notice that in the list the code is more complex. Instead of simply being `44` it's `\033[44m`. It's because this way it tells python that it's an escape code and not just some random number. In the theme you may just put the number. The conversion is done for you.
+
+## 256 colors
+
+For 256 colors you may use a more complex code. For example:
+
+```
+{"bdma":"48;5;124",
+"tbma":"38;5;207"}
+```
+
+In this case `bdma` ( background dark magenta ) is overwritten by a fancy dark red and `tbma` ( text bright magenta ) is overwritten with a bright purple. You can see that the code for the background starts with `48;5` and the code for the text starts with `38;5`.
+
+The full range of the 256 colors. Plus explanation for the entire system you can find [on wikipedia here.](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit)
+
+# Full RGB
+
+Now the most interesting. The full RGB color. This one is quite simple in concept. So let's look at our example.
+
+```
+{"bdma":"48;2;255;0;0",
+"tbma":"38;2;0;255;0"}
+```
+You can see that this one is similar to the 256 colors. But it has a more complex number. For example the `5` in the 256 colors was changed to `2`. And the rest are the 3 numbers of the RGB from 0 to 255.
+
+So the first one will overwrite the `bdma` to red. And the second will overwrite the `tbma` to green.

+ 18 - 3
run.py

@@ -29,8 +29,14 @@
 
 import os
 
+from flbry import variables
 from flbry.variables import *
 
+from flbry import settings
+settings.check_config()
+
+settings.set_theme(settings.get("theme"))
+
 # A welcome logo. 
 logo()
 
@@ -58,7 +64,7 @@ from flbry import trending
 from flbry import url
 from flbry import publish
 from flbry import comments
-from flbry import settings
+
 
 
 
@@ -67,7 +73,8 @@ from flbry import settings
 # again. Forever. Until the user exits.
 
 # List of commands for autocomplete feature.
-complete([
+
+main_commands = [
     "exit",
     "quit",
     "help",
@@ -95,7 +102,9 @@ complete([
     "subscriptions",
     "install",
     "install_force"
-])
+]
+
+complete(main_commands)
 
 while True:
     command = input(typing_dots()) # the : will be the presented function
@@ -199,6 +208,9 @@ while True:
     elif command == "install_force":
         settings.install_desktop(True)
 
+    elif command == "settings":
+        settings.ui()
+
     # If a user types anything ELSE, except just simply pressing
     # Enter. So if any text is in the command, but non of the
     # above were activated.
@@ -209,3 +221,6 @@ while True:
     
     elif command:
         url.get(command)
+
+    # Restore the commands completion
+    complete(main_commands)

+ 6 - 0
themes/BlenderDumbass2.0.json

@@ -0,0 +1,6 @@
+{"bdma":"48;2;254;183;2",
+ "bdbu":"48;2;53;56;73",
+ "bbbu":"48;2;44;47;61",
+ "bdcy":"48;2;254;183;2",
+ "bbma":"48;2;254;183;2",
+ "bdgr":"48;2;44;47;61"}

+ 6 - 0
themes/LBRY_Desktop.json

@@ -0,0 +1,6 @@
+{"bdma":"48;2;31;31;34",
+ "bdbu":"48;2;39;39;42",
+ "bbbu":"48;2;82;82;91",
+ "bdcy":"48;2;62;103;93",
+ "bbma":"48;2;62;103;93",
+ "bdgr":"48;2;64;68;74"}

+ 6 - 0
themes/Mastodon.json

@@ -0,0 +1,6 @@
+{"bdma":"48;2;40;44;55",
+ "bdbu":"48;2;31;35;43",
+ "bbbu":"48;2;36;39;49",
+ "bdcy":"48;2;43;144;217",
+ "bbma":"48;2;43;144;217",
+ "bdgr":"48;2;53;73;71"}

+ 7 - 0
themes/NotAbug.json

@@ -0,0 +1,7 @@
+{"bdma":"48;2;66;139;202",
+ "bdbu":"48;2;255;255;255",
+ "bbbu":"48;2;249;250;251",
+ "bdcy":"48;2;33;186;69",
+ "bbma":"48;2;66;139;202",
+ "bdgr":"48;2;232;232;232",
+ "tbwh":"38;2;0;0;0"}

+ 43 - 0
themes/default.json

@@ -0,0 +1,43 @@
+{
+    "nor":"00",
+    "bold":"01", 
+    "ital":"03", 
+    "undr":"04", 
+    "blnk":"05", 
+    
+
+    "tdbl":"30", 
+    "tdrd":"31", 
+    "tdgr":"32", 
+    "tdyl":"33", 
+    "tdbu":"34", 
+    "tdma":"35", 
+    "tdcy":"36", 
+    "tdwh":"37", 
+    
+    "tbbl":"90", 
+    "tbrd":"91", 
+    "tbgr":"92", 
+    "tbyl":"93", 
+    "tbbu":"94", 
+    "tbma":"95", 
+    "tbcy":"96", 
+    "tbwh":"97", 
+  
+    "bdbl":"40", 
+    "bdrd":"41", 
+    "bdgr":"42", 
+    "bdyl":"43", 
+    "bdbu":"44", 
+    "bdma":"45", 
+    "bdcy":"46", 
+    "bdwh":"47",
+    "bbbl":"100",
+    "bbrd":"101",
+    "bbgr":"102", 
+    "bbyl":"103", 
+    "bbbu":"104",
+    "bbma":"105", 
+    "bbcy":"106", 
+    "bbwh":"108" 
+}

+ 0 - 0
themes/odysee.json


Some files were not shown because too many files changed in this diff