Skip to content
Snippets Groups Projects
Select Git revision
  • 5d96f05f0b70c184d997d193829248893dbe49f9
  • master default
2 results

Module.cs

Blame
  • Module.cs 16.95 KiB
    // i3csstatus - Alternative generator of i3 status bar written in c#
    // (c)   2022 Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
    
    // This program is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License, or
    // any later version.
    
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    
    // You should have received a copy of the GNU General Public License
    // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    using System.IO;
    
    using System.Text.Json;
    using System.Text.Json.Nodes;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    
    using System.CommandLine;
    using System.Runtime.InteropServices;
    
    using Color = System.Drawing.Color;
    using Process = System.Diagnostics.Process;
    using System.Net.Http;
    
    using Config;
    
    namespace i3csstatus;
    
    class FormatExpander
    {
    	static public string Expand(string f, Func<string, string> callback)
    	{
    		StringBuilder sb = new();
    		StringBuilder arg = null;
    		bool freeClosing = false;
    		foreach(char c in f)
    		{
    			if(arg == null && c == '{') arg = new();
    			else
    			if(arg != null && c == '{')
    			{
    				sb.Append('{');
    				arg = null;
    			}
    			else
    			if(arg == null && c == '}')
    			{
    				if(freeClosing) sb.Append('}');
    				freeClosing = !freeClosing;
    			}
    			else
    			if(arg != null && c == '}')
    			{
    				sb.Append(callback(arg.ToString()));
    				arg = null;
    			}
    			else
    			if(arg != null)
    				arg.Append(c);