예제 #1
0
async def main(connection):
    monitor_args = (connection, iterm2.VariableScopes.APP, "effectiveTheme",
                    None)
    async with iterm2.VariableMonitor(*monitor_args) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()

            # Themes have space-delimited attributes, one of which will be light or dark.
            parts = theme.split(" ")
            if "dark" in parts:
                preset = await iterm2.ColorPreset.async_get(
                    connection, "Dracula")
                font = FontSpec('FiraCodeRoman', 15, 'Regular')
            else:
                preset = await iterm2.ColorPreset.async_get(
                    connection, "one-light-terminal")
                font = FontSpec('FiraCodeRoman', 15, 'Medium')

            # Update the list of all profiles and iterate over them.
            profiles = await iterm2.PartialProfile.async_query(connection)
            for partial in profiles:
                # Fetch the full profile and then set the color preset in it.
                profile = await partial.async_get_full_profile()

                new_font = font.to_string()
                print(new_font)
                await profile.async_set_normal_font(new_font)
                # await change.async_set_color_preset(preset)
                await profile.async_set_color_preset(preset)
예제 #2
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    await update(connection, await app.async_get_variable("effectiveTheme"))
    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, "effectiveTheme", None) as mon:
        while True:
            theme = await mon.async_get()
            await update(connection, theme)
예제 #3
0
async def main(connection):
    global lastTheme

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            now = datetime.datetime.now()
            hour = now.hour

            theme = darkTheme

            if hour >= lystFra and hour <= lystTil:
                theme = lightTheme

            if theme == lastTheme:
                continue

            lastTheme = theme
            preset = await iterm2.ColorPreset.async_get(connection, theme)

            # Update the list of all profiles and iterate over them.
            profiles = await iterm2.PartialProfile.async_query(connection)
            for partial in profiles:
                # Fetch the full profile and then set the color preset in it.
                profile = await partial.async_get_full_profile()
                await profile.async_set_color_preset(preset)
                print(theme)
예제 #4
0
async def main(connection):
    async def update(theme):
        # Themes have space-delimited attributes, one of which will be light or dark.
        parts = theme.split(" ")
        if "dark" in parts:
            preset = await iterm2.ColorPreset.async_get(connection, "one-dark")
        else:
            preset = await iterm2.ColorPreset.async_get(connection, "one-light")

        # Update the list of all profiles and iterate over them.
        profiles=await iterm2.PartialProfile.async_query(connection)
        for partial in profiles:
            # Fetch the full profile and then set the color preset in it.
            profile = await partial.async_get_full_profile()
            await profile.async_set_color_preset(preset)

    app = await iterm2.async_get_app(connection)
    theme = await app.async_get_variable("effectiveTheme")
    await update(theme)

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, "effectiveTheme", None) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()
            await update(theme)
예제 #5
0
async def main(connection):
    await update_theme(connection)
    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as monitor:
        while True:
            # Block until theme changes
            _ = await monitor.async_get()
            await update_theme(connection)
예제 #6
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    theme = await app.async_get_variable("effectiveTheme")
    await set_theme(connection, theme)
    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()
            await set_theme(connection, theme)
예제 #7
0
async def switch_on_theme_change(connection):
    """Continuously monitor the effective theme for changes."""
    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            theme = await mon.async_get()
            is_dark = theme_switcher.is_dark_theme(theme)
            preset = await theme_switcher.get_colour_preset(
                connection, is_dark)
            ansi_8_color = theme_switcher.get_ansi_8_color(is_dark)
            await theme_switcher.set_colours(connection, preset, ansi_8_color)
예제 #8
0
async def main(connection):
    app = await iterm2.async_get_app(connection)
    theme = await app.async_get_theme()
    preset = await _get_preset(connection, theme)
    await _set_preset(connection, preset)

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, 'effectiveTheme', None) as mon:
        while True:
            e_theme = await mon.async_get()
            preset = await _get_preset(connection, e_theme)
            await _set_preset(connection, preset)
예제 #9
0
async def main(connection):
    asyncio.ensure_future(quit(connection), loop=asyncio.get_event_loop())

    ast = AutoSwtichTheme(connection, THEME_LIGHT, THEME_DARK)
    await ast.set_color_preset(await ast.get_theme())

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()
            # Set preset if theme has changed
            await ast.set_color_preset(theme)
예제 #10
0
async def main(connection):
    # Set color scheme correctly at app start
    app = await iterm2.async_get_app(connection)
    parts = await app.async_get_theme()
    await changeTheme(parts, connection)

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()
            parts = theme.split(" ")
            await changeTheme(parts, connection)
예제 #11
0
async def main(connection) -> None:

    app = await iterm2.async_get_app(connection)
    initial_theme: str = await app.async_get_theme()
    await changeTheme(connection, initial_theme)

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      'effectiveTheme', None) as mon:
        while True:
            # Block until theme changes
            theme: str = await mon.async_get()

            # Themes have space-delimited attributes, one of which will be light or dark.
            await changeTheme(connection, theme)
예제 #12
0
async def main(conn):
    async with iterm2.VariableMonitor(conn, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            theme = await mon.async_get()
            if "dark" in theme.split():
                shade = "Dark"
            else:
                shade = "Light"
            preset = await iterm2.ColorPreset.async_get(
                conn, f"Gruvbox {shade}")
            for partial in await iterm2.PartialProfile.async_query(conn):
                profile = await partial.async_get_full_profile()
                await profile.async_set_color_preset(preset)
예제 #13
0
async def main(connection):

    app = await iterm2.async_get_app(connection)
    window = app.current_window
    initial_theme = await app.async_get_theme()
    await changeTheme(connection, initial_theme)

    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()
            # Themes have space-delimited attributes, one of which will be light or dark.
            parts = theme.split(" ")
            await changeTheme(connection, parts)
예제 #14
0
async def MonitorSession(connection, session, stack, stack_index, variable,
                         profile_map):
    profile_name = await session.async_get_variable(variable)
    AddToStack(stack, stack_index, profile_name, profile_map)
    await SelectProfile(connection, session, stack)

    async with iterm2.VariableMonitor(connection,
                                      iterm2.VariableScopes.SESSION, variable,
                                      session.session_id) as mon:
        while True:
            profile_name = await mon.async_get()
            AddToStack(stack, stack_index, profile_name, profile_map)
            print("Profile stack has been updated")
            print(stack)
            await SelectProfile(connection, session, stack)
예제 #15
0
async def main(connection):
    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            # Block until theme changes
            theme = await mon.async_get()

            if exists("/usr/bin/python3"):
                python_path = "/usr/bin/python3"
            elif exists("/usr/local/bin/python3"):
                python_path = "/usr/local/bin/python3"
            else:
                raise RuntimeError("Cannot find python3 executable.")

            pwsh_args = [
                python_path,
                expanduser("~/.dotfiles/scripts/nvim.py"),
                "--command",
            ]

            # Themes have space-delimited attributes, one of which will be
            # light or dark.
            parts = theme.split(" ")
            if "dark" in parts:
                preset = await iterm2.ColorPreset.async_get(
                    connection, "cosmic_latte_dark")
                pwsh_args.append("set background=dark")
                with open(expanduser("~/.dotfiles/pwsh/tmp_dirs/system_theme"),
                          "w") as file_handle:
                    file_handle.write("dark")
            else:
                preset = await iterm2.ColorPreset.async_get(
                    connection, "cosmic_latte_light")
                pwsh_args.append("set background=light")
                with open(expanduser("~/.dotfiles/pwsh/tmp_dirs/system_theme"),
                          "w") as file_handle:
                    file_handle.write("light")

            run(pwsh_args)

            # Update the list of all profiles and iterate over them.
            profiles = await iterm2.PartialProfile.async_query(connection)
            for partial in profiles:
                # Fetch the full profile and then set the color preset in it.
                profile = await partial.async_get_full_profile()
                await profile.async_set_color_preset(preset)
예제 #16
0
async def main(connection):
    # Set colors initially because of unknown profile defaults
    app = await iterm2.app.async_get_app(connection)
    dark_theme = await is_dark_theme(app=app)
    await set_dark_colors(connection, dark_theme)
    dark_colors = dark_theme

    # Begin monitoring the effective theme
    async with iterm2.VariableMonitor(
        connection,
        iterm2.VariableScopes.APP,
        "effectiveTheme",
        None,
    ) as monitor:
        while True:
            dark_theme = await is_dark_theme(monitor=monitor)
            if dark_theme != dark_colors:
                await set_dark_colors(connection, dark_theme)
                dark_colors = dark_theme
예제 #17
0
async def main(connection: iterm2.connection.Connection):
    app = await iterm2.app.async_get_app(connection)

    # Set colors initially because of unknown profile defaults
    is_dark = await is_dark_theme(app)
    await set_color_presets(connection, is_dark)
    was_dark = is_dark

    # Begin monitoring the effective theme
    async with iterm2.VariableMonitor(
        connection,
        iterm2.VariableScopes.APP,
        "effectiveTheme",
        None,
    ) as monitor:
        while True:
            is_dark = await is_dark_theme(monitor)
            if is_dark != was_dark:
                await set_color_presets(connection, is_dark)
                was_dark = is_dark
예제 #18
0
async def main(connection):
    # Set colors initially because of unknown profile defaults
    app = await iterm2.app.async_get_app(connection)
    session = app.current_terminal_window.current_tab.current_session

    dark_theme = await is_dark_theme(app=app)
    await set_dark_colors(connection, dark_theme)
    dark_colors = dark_theme

    # Begin monitoring the effective theme
    async with iterm2.VariableMonitor(
        connection,
        iterm2.VariableScopes.APP,
        "effectiveTheme",
        None,
    ) as monitor:
        while True:
            dark_theme = await is_dark_theme(monitor=monitor)
            if dark_theme != dark_colors:
                await set_dark_colors(connection, dark_theme)
                #await session.async_send_text("tmux source-file ~/.tmux.conf\n")
                dark_colors = dark_theme